HDU4952:Number Transformation

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

找规律= =
#include <stdio.h>

int main()
{
    __int64 a,b,cas=1,i,j;
    while(~scanf("%I64d%I64d",&a,&b),a+b)
    {
        i=2;
        while(i<=b)
        {
            if(a%i)
            {
                j=a/i+1;
                if(j<=i)
                {
                    a=j*b;
                    break;
                }
                a=i*j;
            }
            else
            {
                j=a/i;
                if(j<=i)
                {
                    a=j*b;
                    break;
                }
            }
            i++;
        }
        printf("Case #%I64d: %I64d\n",cas++,a);
    }
    return 0;
}

HDU4952:Number Transformation

时间: 2024-08-29 23:38:31

HDU4952:Number Transformation的相关文章

hdu4952 Number Transformation(数学题 | 找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4952 Number Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 261    Accepted Submission(s): 117 Problem Description Teacher Mai has

HDU-4952 Number Transformation

http://acm.hdu.edu.cn/showproblem.php?pid=4952 Number Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 171    Accepted Submission(s): 69 Problem Description Teacher Mai has an inte

数论 Number Transformation HDU4952

已知n,k,操作k次,每次操作求大于n且能被次数i整除的最小的数 已知x*i,所以(i+1)*y>=x*i,y>=x-[x/(i+1)],当x<i+1时,y的值不再改变,直接break,输出y*k即可(x,y都是倍数) #include <stdio.h> int main() { long long n,k; long long i; int time=0; while(scanf("%I64d%I64d",&n,&k)!=-1) { i

hdu 4952 Number Transformation (找规律)

题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值,求出这个固定的值和K相乘就可以了, 为什么会趋于固定的值呢,因为最后虽然i在不断增长,但是x也是在增长的,每次的倍数会回退一个发现 有余数,然后再加上一个,所以趋于稳定. 官方题解: 1 #include <iostream> 2 #include <cstdio> 3 #includ

Codeforces 346C Number Transformation II 构造

题目链接:点击打开链接 = = 990+ms卡过 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<set> using namespace std; #define N 100010 #define L(x) (x<<1) #define R(x) (x<<

HDU 4952 Number Transformation(公式)

HDU Number Transformation 题目链接 题意:按题目中要求求出最后的n 思路:推公式(i+1)x′>=ix,得到x′>=1+floor(xi+1),这样一来就可以递推x,那么注意题目中k很大,但是实际上如果i到一定数值之后,x就不会在增长了,这时候就可以break了 代码: #include <cstdio> #include <cstring> typedef long long ll; ll n, k; int main() { int cas

HDU 4952 Number Transformation 乱搞

题意:给你一个数x,给你K次操作,每一次x变为大于等于 x 且是 i 的倍数的数. 解题思路:可以知道  如果 变化以后  x 是i 和 i+1 的公倍数的倍数的话,那么x的值是不会变的,x  < i * i 的时候,x值肯定会变,每一次增大i(这里后面就可以直接用公式) 所以我们只需要枚举到前面那种情况就可以了. 解题代码: 1 // File Name: 1008.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月14日 星期四 13

Codeforces 251C Number Transformation

Number Transformation 我们能发现这个东西是以2 - k的lcm作为一个循环节, 然后bfs就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int,

CodeForces 346C Number Transformation II

Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数. 也就是说 [ k * x[i] + 1,  (k+1)* x[i] -1 ]这段区间的的数都会走到 k * x[i]上. 所以对于每个位置都先计算出他到右边最远的覆盖位置. 然后在反着求出每个位置能往左走走到的最远的位置. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freo