Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Why Runtime Error?(C++)//2649_2 #include <stdio.h> #include <math.h> bool ss[66000]={0}; int main() { unsigned int i,j,sqrti,m,mm,n,nn; for(i=3;i<66000;i++) { sqrti=int(sqrt(i)); for(j=2;j<=sqrti;j++) if(i%j==0) { ss[i]=1; break; } } bool ans; while(scanf("%d%d",&n,&m)==2) { mm=m;nn=n; if(m==0){ans=0; goto end;} for(n=2;n<=nn;n++) { j=n; for(i=2;i<66000&&ss[j];i++) { while(j%i==0) { if(m%i==0) m/=i; j/=i; } } if(m%j==0) m/=j; if(m==1) break; } if(m>1) ans=0; else ans=1; end: if(!ans) printf("%d does not divide %d!\n",mm,nn); else printf("%d divides %d!\n",mm,nn); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator