21: Maximum prime factor sequence, 21-factor sequence
21: maximum quality factor sequence
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Input two positive integers m, n (1 <m <n <= 5000), and output the maximum prime factor (including m and n) of each number from m to n in sequence; if a certain number is a prime number, the output is itself ).
-
Input
-
A row contains two positive integers m and n separated by a single space.
-
Output
-
The maximum quality factor of each integer in one row, separated by commas.
-
Sample Input
-
5 10
-
Sample output
-
5,3,7,2,3,5
-
Source
-
Yuan Pei-From Whf
-
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 int vis[10001]; 6 int main() 7 { 8 int m,n; 9 cin>>m>>n;10 for(int i=2;i<=sqrt(n+0.5);i++)11 {12 if(vis[i]==0)13 {14 for(int j=i*i;j<=n;j=j+i)15 {16 vis[j]=1;17 }18 }19 }20 int flag=0;21 for(int i=m;i<=n;i++)22 {23 if(vis[i]==0&&flag==1)24 {25 cout<<","<<i;26 }27 else if(vis[i]==0&&flag==0)28 {29 cout<<i;30 flag=1;31 }32 else33 {34 for(int j=i-1;j>=2;j--)35 {36 if(i%j==0&&vis[j]==0)37 {38 if(flag==1)39 cout<<","<<j;40 else 41 {42 cout<<j;43 flag=1;44 }45 break;46 }47 48 }49 }50 }51 return 0;52 }