首页 > 代码库 > hdu 1164 Eddy's research I

hdu 1164 Eddy's research I

 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<string> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 #define MAX 65535 9 int prime[MAX+5];10 bool vis[MAX+5];11 int index=0;12 void get_prime(){13     memset(vis,false,sizeof(vis));14     int i=2;15     //int sum=0;16     for(;i<=MAX;i++){17         if(!vis[i]){18             prime[index++]=i;19         }20         int j=0;21         for(;j<index&&i*prime[j]<=MAX;j++){22             vis[i*prime[j]]=true;23             //sum++;24             if(i%prime[j]==0){25                 break;26             }27         }28     }29     /*i=0;30     for(;i<index;i++){31         cout<<i<<‘ ‘<<prime[i]<<endl;32     }*/33     //cout<<"1"<<‘ ‘<<sum<<endl;34 }35 int main()36 {37     //freopen("INPUT.txt", "r", stdin);38     get_prime();39     int n;40     while(cin>>n){41         int j=0;42         for(;j<index&&n>1;j++){43             if(n%prime[j]==0){44                 //cout<<j<<"***"<<prime[j]<<endl;45                 n/=prime[j];46                 cout<<prime[j];47                 while(n%prime[j]==0){48                     n/=prime[j];49                     cout<<"*"<<prime[j];50                 }51                 break;52             }53         }54         for(;j<index&&n>1;j++){55             while(n%prime[j]==0){56                     n/=prime[j];57                     cout<<"*"<<prime[j];58                 }59         }60         cout<<endl;61     }62     return 0;63 }

素数分解与输出,注意输出格式

hdu 1164 Eddy's research I