Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 418 Accepted Submission(s): 201
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 10 #define N 1505 11 #define M 15 12 #define mod 1000000007 13 #define mod2 100000000 14 #define ll long long 15 #define maxi(a,b) (a)>(b)? (a) : (b) 16 #define mini(a,b) (a)<(b)? (a) : (b) 17 18 using namespace std; 19 20 ll x,k,i,tmp; 21 int cnt; 22 /* 23 void ini() 24 { 25 int i,k,j; 26 for(i=1;i<=15;i++){ 27 for(k=1;k<=15;k++){ 28 int x=i; 29 for(j=1;j<=k;j++){ 30 while(x%j!=0){ 31 x++; 32 } 33 } 34 printf(" i=%d k=%d x=%d\n",i,k,x); 35 } 36 } 37 }*/ 38 39 int main() 40 { 41 //ini(); 42 //freopen("data.in","r",stdin); 43 //scanf("%d",&T); 44 //for(int cnt=1;cnt<=T;cnt++) 45 //while(T--) 46 cnt=1; 47 while(scanf("%I64d%I64d",&x,&k)!=EOF) 48 { 49 if(x==0 && k==0) break; 50 printf("Case #%d: ",cnt);cnt++; 51 tmp=-1; 52 for(i=1;i<=k;i++){ 53 if(x%i!=0){ 54 x=(x/i+1)*i; 55 56 } 57 if(x%i==0 && (x/i)==i-1){ 58 //printf(" i=%I64d i-1=%I64d x=%I64d\n",i,x/(i),x); 59 tmp=x/i; 60 break; 61 } 62 } 63 if(tmp==-1){ 64 printf("%I64d\n",x); 65 } 66 else printf("%I64d\n",tmp*(k-i)+x); 67 } 68 69 70 71 return 0; 72 }
原文:http://www.cnblogs.com/njczy2010/p/3913541.html