3858: Number Transformation

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 82  Solved: 41
[Submit][Status]

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

HINT

Source

  其实我也不知道怎么证明,反正通过实验发现n/i每次严格减小到一个极限值,就再也不会变了,而这个极限值在sqrt(n)范围,迭代次数也是sqrt(n)的。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long qword;
int main()
{
freopen("input.txt","r",stdin);
qword n,m;
int i;
qword t;
int cnt=;
while (scanf("%lld%lld",&n,&m),cnt++,n+m)
{
t=;
for (i=;i<=m;i++)
{
n=(n/i+(n%i!=))*i;
if (n/i==t)break;
t=n/i;
}
printf("Case #%d: %lld\n",cnt,m*t);
}
}

bzoj 3858: Number Transformation 暴力的更多相关文章

  1. hdu4952 Number Transformation (找规律)

    2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...

  2. HDU-4952 Number Transformation

    http://acm.hdu.edu.cn/showproblem.php?pid=4952 Number Transformation Time Limit: 2000/1000 MS (Java/ ...

  3. CodeForces346 C. Number Transformation II

    C. Number Transformation II time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. Codeforces 251C Number Transformation

    Number Transformation 我们能发现这个东西是以2 - k的lcm作为一个循环节, 然后bfs就好啦. #include<bits/stdc++.h> #define L ...

  5. LightOJ 1141 Number Transformation

    Number Transformation In this problem, you are given an integer number s. You can transform any inte ...

  6. CodeForces 346C Number Transformation II

    Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数. 也就是说 [ k * x[i] + 1,  (k+1)* x ...

  7. BZOJ 3275: Number

    3275: Number Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 874  Solved: 371[Submit][Status][Discus ...

  8. Number Transformation

    Description In this problem, you are given a pair of integers A and B. You can transform any integer ...

  9. Easy Number Challenge(暴力,求因子个数)

    Easy Number Challenge Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

随机推荐

  1. iOS开源项目推荐|下拉刷新

    MJRefresh - 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明. CBStoreHouseRefresh ...

  2. Java Interface and Abstraction

    本文引用资源申明: http://blog.csdn.net/xw13106209/article/details/6923556 http://www.cnblogs.com/dolphin0520 ...

  3. JMS—事务管理

    Spring提供了一个JmsTransactionManager用于对JMS ConnectionFactory做事务管理.这将允许JMS应用利用Spring的事务管理特性.JmsTransactio ...

  4. react环境搭建

    react-webpack文件夹是开发目录,在此目录下执行命令,假设你已经正确安装了 nodejs 一:参照教程搭建环境 https://github.com/newtriks/generator-r ...

  5. JAVA的instanceOf什么时候用啊

    当你拿到一个对象的引用时(例如参数),你可能需要判断这个引用真正指向的类.所以你需要从该类继承树的最底层开始, 使用instanceof操作符判断,第一个结果为true的类即为引用真正指向的类. cl ...

  6. CDN调度器HAProxy、Nginx、Varnish

    http://www.ttlsa.com/web/the-cdn-scheduler-nginx-haproxy-varnish/ CDN功能如下:1.将全网IP分为若干个IP段组,分组的依据通常是运 ...

  7. V$SESSION_LONGOPS

    对大部分DBA来说,V$SESSION_LONGOPS视图都不会陌生,以前在面试的时候,也有一些企业会问到如何查询数据库中运行时间比较长的SQL,就可以通过这个视图来查看.V$SESSION_LONG ...

  8. prototype原型链继承

    依旧是恶补js基础,上代码: 1.定义父类及父类方法 function Animal(){ this.name = "动物"; } Animal.prototype.eat = f ...

  9. UVA 11991 Easy Problem from Rujia Liu?(vector map)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  10. 用crontab、crond在嵌入式系统中添加定时任务

    在嵌入式系统中,定时任务通过crond和cronttab两个系统命令来联合执行. 其中crond是定时任务的守护进程,系统开始时是没有开启的.crontab主要作用是管理用户的crontab file ...