码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 4952

时间:2014-08-14 23:45:06      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   java   os   io   

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 10 2520 20 0 0
 
Sample Output
Case #1: 2520 Case #2: 2600
 
Source
 
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 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 }

 

hdu 4952,布布扣,bubuko.com

hdu 4952

标签:des   style   blog   http   color   java   os   io   

原文地址:http://www.cnblogs.com/njczy2010/p/3913541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!