您的位置:首页 > 大数据 > 人工智能

HDU 4952 Number Transformation(数学)——2014 Multi-University Training Contest 8

2016-09-17 11:04 531 查看
传送门

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: