HDU 4952 Number Transformation(数学)——2014 Multi-University Training Contest 8
2016-09-17 11:04
591 查看
传送门
Total Submission(s): 1173 Accepted Submission(s): 562
[align=left]Problem Description[/align] 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.
[align=left]Input[/align] 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).
[align=left]Output[/align] For each test case, output one line "Case #k: x", where k is the case number counting from 1.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
题目大意:
有一个数 x 每经过 i 次之后都会变成大于等于 i 的倍数,那么现在让你求 经过 k 次之后 x 将变成什么?
解题思路:
根据题目的意思,如果当前的 x 是 i 的倍数的话就不需要考虑,那么我们现在就是考虑 x mod i!=0的情况,我们可以列出一个方程:i∗x≤(i+1)∗y,
那么我们现在将这个式子转化一下就是:y≥i∗xi+1 ==> y≥x−xi+1 根据这个式子显然有 当 x<(i+1) 的时候这个当前的
值是不变的,也就是直接变为 tmp∗k(tmp = x/(i+1)) 否则的话将转化为最小 i 的倍数。
My Code:
Number Transformation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1173 Accepted Submission(s): 562
[align=left]Problem Description[/align] 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.
[align=left]Input[/align] 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).
[align=left]Output[/align] For each test case, output one line "Case #k: x", where k is the case number counting from 1.
[align=left]Sample Input[/align]
2520 10 2520 20 0 0
[align=left]Sample Output[/align]
Case #1: 2520 Case #2: 2600
题目大意:
有一个数 x 每经过 i 次之后都会变成大于等于 i 的倍数,那么现在让你求 经过 k 次之后 x 将变成什么?
解题思路:
根据题目的意思,如果当前的 x 是 i 的倍数的话就不需要考虑,那么我们现在就是考虑 x mod i!=0的情况,我们可以列出一个方程:i∗x≤(i+1)∗y,
那么我们现在将这个式子转化一下就是:y≥i∗xi+1 ==> y≥x−xi+1 根据这个式子显然有 当 x<(i+1) 的时候这个当前的
值是不变的,也就是直接变为 tmp∗k(tmp = x/(i+1)) 否则的话将转化为最小 i 的倍数。
My Code:
/** 2016 - 09 - 16 晚上 Author: ITAK Motto: 今日的我要超越昨日的我,明日的我要胜过今日的我, 以创作出更好的代码为目标,不断地超越自己。 **/ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <algorithm> #include <set> using namespace std; typedef long long LL; typedef unsigned long long ULL; const LL INF = 1e9+5; const LL MAXN = 1e5+5; const LL MOD = 998244353; const double eps = 1e-7; const double PI = acos(-1); using namespace std; int Scan_Int()///输入外挂 { int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } LL Scan_LL()///输入外挂 { LL res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } void Out(LL a)///输出外挂 { if(a>9) Out(a/10); putchar(a%10+'0'); } int main() { LL x, k; int cas = 1; while(cin>>x>>k) { if(x==0 && k==0) break; LL ans = x, i = 1, tmp; while(i <= k) { if(x % i != 0) { tmp = x / i + 1; if(tmp > i) x = tmp * i; else { x = tmp * k; break; } } i++; } printf("Case #%d: %I64d\n",cas++,x); } return 0; }
相关文章推荐
- hdu 4952 Number Transformation--2014 Multi-University Training Contest 8
- hdu 4968 Just a Joke 数学(积分) 2014 Multi-University Training Contest 9-1010
- hdu 4864 Task---2014 Multi-University Training Contest 1
- HDU 4864 (2014 Multi-University Training Contest 1 )
- HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)
- 【2014 Multi-University Training Contest 3 1002】/【HDU 4888】 Redraw Beautiful Drawings
- HDU 4897 Little Devil I(树链剖分)(2014 Multi-University Training Contest 4)
- HDU 4869 Turn the pokers (2014 Multi-University Training Contest 1)
- 【HDU 2014 Multi-University Training Contest 1 1002】/【HDU 4862】Jump
- HDU 4890 One to Four(2014 Multi-University Training Contest 3)
- hdu 4861 Couple doubi ---2014 Multi-University Training Contest 1
- hdu 4891The Great Pan -----------2014 Multi-University Training Contest 3
- hdu 4876 ZCC loves cards 2014 Multi-University Training Contest 2
- hdu 4893 Wow! Such Sequence!(线段树和树状数组实现)--2014 Multi-University Training Contest 3
- 【2014 Multi-University Training Contest 3 1002】/【HDU 4888】 Redraw Beautiful Drawings
- 【2014 Multi-University Training Contest 3 1007】/【HDU 4893】 Wow! Such Sequence!
- HDU 4870 Rating (2014 Multi-University Training Contest 1)
- hdu4869 Turn the pokers 2014 Multi-University Training Contest 1
- hdu 4891 The Great Pan---2014 Multi-University Training Contest 3
- hdu 4902 Nice boat--2014 Multi-University Training Contest 4