首页 > 代码库 > hdu 4952

hdu 4952

Number Transformation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 418    Accepted Submission(s): 201

Problem Description
   Teacher Mai has an integer x.
   He does the following operations k times. In the i-th operation, x becomes the least integer no less than x, which is the multiple of i.
   He wants to know what is the number x now.
 
Input
   There are multiple test cases, terminated by a line "0 0".
   For each test case, the only one line contains two integers x,k(1<=x<=10^10, 1<=k<=10^10).
 
Output
   For each test case, output one line "Case #k: x", where k is the case number counting from 1.
 
Sample Input
2520 102520 200 0
 
Sample Output
Case #1: 2520Case #2: 2600
 
Source
2014 Multi-University Training Contest 8
 
Recommend
hujie
 
 
必须强调,不会的题一定不要偷懒,打表!!!!!!!!!!!!!!
 
 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 150511 #define M 1512 #define mod 100000000713 #define mod2 10000000014 #define ll long long15 #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 }