标签:des style http color os io strong for
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 572 | Accepted: 198 |
Description
Input
Output
Sample Input
168 882 770 792 0 0
Sample Output
1. 3:4 2. 5:6
Source
#include<cstdio> #include<cmath> #include<iostream> #include<cstring> #include<algorithm> #include<cstdlib> using namespace std; const int maxn=1000000+10; int prime[maxn],vis[maxn],num[2][maxn]; int cal; int init() { int c=0,m; memset(vis,0,sizeof(vis)); m=sqrt(maxn+0.5); for(int i=2;i<=m;i++) { if(!vis[i]) { for(int j=i*i;j<=maxn;j+=i) vis[j]=1; } } for(int i=2;i<=maxn;i++) { if(!vis[i]) prime[++c]=i; } return c; } void solve(int ith,int x) { for(int i=1;i<=cal;i++) num[ith][i]=0; for(int i=1;i<=cal&&x>=prime[i];i++) { while(x%prime[i]==0) { num[ith][i]++; x=x/prime[i]; } if(x==1) break; } } int main() { int cas=1,a,b,ans,max_ans; cal=init(); while(~scanf("%d%d",&a,&b)) { max_ans=ans=0; if(a==0&&b==0) return 0; for(int i=1;i<=cal;i++) { if(a%prime[i]==0||b%prime[i]==0) ans++; } solve(0,a); solve(1,b); for(int i=1;i<=cal;i++) max_ans=max_ans+abs(num[0][i]-num[1][i]); printf("%d. %d:%d\n",cas++,ans,max_ans); } return 0; }
poj3993Not So Flat After All(筛法素数+分解质因子),布布扣,bubuko.com
poj3993Not So Flat After All(筛法素数+分解质因子)
标签:des style http color os io strong for
原文地址:http://blog.csdn.net/u014303647/article/details/38413005