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 |
用 欧拉函数, 然后枚举, 但是我按解题报告这么做的怎么那么慢In Reply To:强人们看看我怎么老是WA? 内有代码. Posted by:wronger at 2006-03-26 23:08:10 > #include <stdio.h> > #include <math.h> > > int a[30]; > > void seta(int a[], int m){ > int i, j; > a[0]=0; j=1; > for( i=2; m>1 ; ){ > if(m%i!=0) i++; > else if(m%i==0){ > m=m/i; > if(i!=a[j-1]){ > a[j++]=i; > a[0]++; > } > } > } > } > > int main(){ > int m, k, r, res, i, j; > while(scanf("%d%d", &m, &k)==2){ > if(m==1){ > printf("%d\n", k); > continue; > } > seta(a, m); > r=m; > for(i=1; i<=a[0]; i++){ > r=r*(a[i]-1)/a[i]; > } > res=k/r*m; > k=k%r; > if(k==0) res--; > for(i=1; k>0; i++){ > for(j=1; a[j]<=i && j<=a[0]; j++){ > if(i%a[j]==0) goto L; > } > k--; > L:; > } > i--; > res+=i; > printf("%d\n", res); > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator