| ||||||||||
| 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 | |||||||||
强人们看看我怎么老是WA? 内有代码.#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