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. linux上安装shell编辑器与linux运维面试题

    分两个部分 一.安装B-shell解释器 安装cygwin  Eclipse要找到安装的bin路径 https://cygwin.com 二.安装编辑器shellEd 下载可以得到一个:net.sou ...

  2. Android开发之Bitmap二次采样

    Bitmap二次采样,听着好像是一个高大上的事,其实也就那么回事,今天我们就来看看Bitmap的二次采样问题. 1.为什么要二次采样 OK,那么首先我要 解决的一个问题就是为什么我们要二次采样? 不知 ...

  3. Android(java)学习笔记159:Dalivk虚拟机的初始化过程

    1.初始化下面系统函数(调用dvmStartup函数初始化所有相关的函数) 开始学习虚拟机的初始化过程,先从dvmStartup函数开始,这个函数实现所有开始虚拟机的准备工作: dvmAllocTra ...

  4. 字符的截取方法使用的是Substring 和三目运算符

    substring(0,m.title.length>11?11:m.title.length)

  5. javascript进击(七)Ajax

    AJAX AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 不是新的编程语言,而是一种使用现有标准的新方法. AJA ...

  6. 深入理解计算机系统第二版习题解答CSAPP 2.5

    分别写出十六进制数0x87654321在大端法机器和小端法机器上第1个.前2个.前3个字节. A.小端法:21    大端法:87 B.小端法:21 43      大端法:87 65 C.小端法:2 ...

  7. Java 并发——多线程基础

    Thead类与Runnable接口 Java的线程,即一个Thread实例. Java的线程执行过程有两种实现方式: 子类继承Thread类,并且重写void run()方法. 自定义类实现Runna ...

  8. Magento强大的配置系统

    Magento的配置系统就像是Magento的心脏,支撑着Magento的运行.这套配置系统掌管着几乎所有"module/model/class/template/etc".它把整 ...

  9. 不同浏览器应用scrollTop属性

    window.onscroll = _onScroll;function _onScroll(){ var aside = document.getElementsByClassName('aside ...

  10. .net中压缩和解压缩的处理

    最近在网上查了一下在.net中进行压缩和解压缩的方法,方法有很多,我找到了以下几种: 1.利用.net自带的压缩和解压缩方法GZip 参考代码如下: //======================= ...