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 |
超时了,哪位有比较好的算法,顺变看看我的代码(内)#include<stdio.h> int main() { int n,i,j,str[1000],m,k,flag=0,num; while(scanf("%d%d",&m,&k)!=EOF) { str[0]=1; j=1; i=2; while(m>=i) { while(m%i==0) { m=m/i; if(i!=str[j-1]) { str[j++]=i; } } i++; } n=k; k--; i=2; while(k) { flag=0; for(num=1;num<j;num++) { if(i%str[num]==0 ||str[num]%i==0) { flag=1; i++; break; } } if(flag==0) { k--; i++; } } if(n==1) printf("1\n"); else printf("%d\n",i-1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator