hdu 5108 Alexandra and Prime Numbers

数论题,本质是求出n的最大质因子

 1 #include<time.h>
 2 #include <cstdio>  
 3 #include <iostream>  
 4 #include<algorithm>
 5 #include<math.h> 
 6 #include <string.h>  
 7 #include<vector> 
 8 #include<queue>
 9 using namespace std;
10 
11 int main()
12 {
13     int n,t;
14     while(scanf("%d",&n)!=EOF)
15     {
16         if(n == 1)  //注意1不是素数,找不到最大质因子 
17         {
18             printf("0
");
19             continue;
20         }
21         
22         else
23         {
24             t=n;
25             int maxx=1;
26             for(int i=2;i<=int(sqrt(n));i++)
27                 while(t%i==0)
28                 {
29                     t/=i;
30                     maxx=i;
31                 }
32             maxx=max(t,maxx);
33             printf("%d
",n/maxx);
34         }
35     }
36     return 0;
37 }
原文地址:https://www.cnblogs.com/pter/p/5409988.html