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 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

2014 Multi-University Training Contest 8

官方题解:http://blog.sina.com.cn/u/1809706204

打表找规律也行!

当时在打表的时候10W是WA,20W是T,最后12W才过!

代码如下:

#include<cstdio>
typedef __int64 LL;
int main()
{
    int cas=1;
    LL i;
    LL x,k;
    while(scanf("%I64d %I64d",&x,&k)!=EOF)
    {
        if(x==0 && k==0)
            break;
        if(k <= 120000)
        {
            for(i = 1; i <= k; i++)
            {
                if(x%i==0)
                    continue;
                else
                    x=(x/i+1)*i;
            }
            printf("Case #%d: ",cas++);
            printf("%I64d\n",x);
        }
        else
        {
            LL y1,y2;
            for(i = 1; i <= 120000; i++)
            {
                if(x%i==0)
                    continue;
                else
                    x=(x/i+1)*i;
            }
            y1=x;
            y2=(x/i+1)*i;
            printf("Case #%d: ",cas++);
            printf("%I64d\n",y1+(k-120000)*(y2-y1));
        }
    }
    return 0;
}

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

时间: 2024-12-24 11:35:27

hdu4952 Number Transformation(数学题 | 找规律)的相关文章

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

HDU 4952 Number Transformation 打表规律

点击打开链接 Number Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 495    Accepted Submission(s): 248 Problem Description Teacher Mai has an integer x. He does the following operation

uva10706 - Number Sequence(找规律)

题目:uva10706 - Number Sequence(找规律) 题目大意:有这样一串序列11212312341234512345612345671234567812345678912345678910123456789101112345678910...,问第i个位置数的值. 1  2     3       4          5            6              7               ... 解题思路:这题需要发现规律.我一开始还看错题意了.规律是看了别人

ZOJ 3622 Magic Number 打表找规律

A - Magic Number Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3622 Appoint description: Description A positive number y is called magic number if for every positive integer x it satisfies that

HDU 1041 Computer Transformation(找规律加大数乘)

主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #include<map> #include<iostream> #include<ctype.h> #include<string> #include<algorithm> #include<stdlib.h> #i

HDOJ-1041 Computer Transformation(找规律+大数运算)

http://acm.hdu.edu.cn/showproblem.php?pid=1041 有一个初始只有一个1的串 每次都按①0 -> 10;②1 -> 01;这两条规则进行替换 形如:n = 1  1 n = 2  01 n = 3  1001 ... 求经过n步替换之后 串中只含复数个0的连续子串(不难发现,这种子串只能是‘00’)的出现次数 因为0<n<=1000的限制 在最坏情况下(n==1000)串的长度将达到2^1000位 排除了直接模拟上述替换过程的可能 列出前几

ACdream1187-Rational Number Tree-模拟/找规律

找到规律模拟就可以了,用DFS模拟很简洁,用循环模拟比较直观(大概吧) 注意输入输出用%llu,1ULL<<64=0!被这几个小问题卡了好久 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int T; unsigned long long n,p,q; unsigned long long path; int lev; int main() { s

uva 10706 Number Sequence(找规律)

uva 10706 Number Sequence A single positive integer iis given. Write a program to find the digit located in the position iin the sequence of number groups S1S2-Sk. Each group Skconsists of a sequence of positive integer numbers ranging from 1 to k, w

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