ideas
simulation.
-
Fast reading. Needless to say about this.
-
Determine prime numbers. This is used to help get the maximum prime factor later. The details are to avoid timeouts. The upper limit of the loop is
sqrt (x)
(remember to add the header fileinclude<cmath>
,unless you use the universal header). -
Obtaining the largest prime factor. Enumerate from largest to smallest! ! Otherwise, an MLE warning will be issued.
-
The main function has nothing to say, it is best to use
printf
it to avoid timeout.
Code
#include<bits/stdc++.h>
using namespace std;
int read (){
int s = 0, x = 1;
char ch = getchar ();
while (ch < '0' or ch > '9'){if (ch == '-') x = -1; ch = getchar ();}
while (ch >= '0' and ch <= '9'){s = s * 10 + ch - '0'; ch = getchar ();}
return s * x;
}
bool pr (int x){
for (int i = 2; i <= sqrt (x); i++) if (x % i == 0) return 0;
return 1;
}
int pd (int x){
if (pr (x)) return x;
for (int i = x - 1; i >= 2; i--){
if (!pr (i)) continue;
if (x % i == 0) return i;
}
}
int n, m;
int main (){
n = read (), m = read ();
for (int i = n; i < m; i++)printf ("%d,",pd (i));
printf ("%d\n", pd (m));
return 0;
}
—— E n d End End——