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. Android(java)学习笔记209:采用get请求提交数据到服务器(qq登录案例)

    1.GET请求:    组拼url的路径,把提交的数据拼装url的后面,提交给服务器. 缺点:(1)安全性(Android下提交数据组拼隐藏在代码中,不存在安全问题)  (2)长度有限不能超过4K(h ...

  2. 页面常见效果js实现

    2015.12.2 页面常见效果js实现 [有没有觉得很坑,[笑哭,邮箱写上]] 复习: Js内置对象: 1.浏览器对象 window document history location event  ...

  3. [Form Builder]内置函数execute_trigger、do_key详解

    转:http://yedward.net/?id=82 1.execute_trigger:用来运行一个指定的触发器,常用来运行用户自定义的触发器. 语法:procedure execute_trig ...

  4. linux的nohup disown setsid screen

    ```nohup 可以将进程挂起 帐号退出时不受影响 nohup cp -r a b/ [>/~/cp.log] & setsid 作用类似于nohup swtsid cp -r a b ...

  5. 3.linux安装vsftpd服务

    1.首先查看本地是否安装了vsftpd rpm -qa |grep vsftpd 2.安装vsftpd: yum install vsftpd 3.查询当前ftp状态 chkconfig --list ...

  6. bubble_sort

    冒泡排序法: #include <iostream> #include <algorithm> using namespace std; int main(){ int n; ...

  7. Android 里面的小坑

    1.listview加了个blockdescen,竟然导致editTextView不能获取焦点

  8. 今天是程序员节(Programmer‘s Day)

    http://blog.jobbole.com/47787/ 我只想知道他们到底在说神马???

  9. iOS 9 Spotlight搜索 OC版

    介绍:    在WWDC 2015会议上,苹果官方公布了iOS9.除开许多新的特性和增强功能,这次升级也给了开发者们一个机会让他们的app里的内容能通过Spotlight 搜索功能被发现和使用.在iO ...

  10. css样式 第6节

    程序员语录: 不要太刻意地把写程序这件事和挣钱挂起来,局限了你挣钱的本事 <html> <head> <title>网页样式</title> </ ...