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. shell 实例脚本

    例1: #!/bin/bashsum=0;for i in {1..100..2}do let "sum+=i"doneecho "the sum is $sum&quo ...

  2. Centos7.0挂载优盘安装jdk1.7和tomcat7.0

    Centos7.0挂载优盘安装jdk1.7和tomcat7.0 前言: 笔者发现用wget方法直接在服务器下载jdk和tomcat速度很慢,而且jdk1.7用wget方法下载链接不好找,不如直接从官网 ...

  3. Android(java)学习笔记147:textView 添加超链接(两种实现方式,,区别于WebView)

    1.方式1: LinearLayout layout = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLa ...

  4. Margin和Padding之间的区别

    margin ,padding body他们之间的区别就是 margin表示的是外边框的距离 padding表示的是内边框的距离 body表示的边框的距离

  5. mysql脚本mysql_safe解释、mysql.sock文件、mysql_install_db

    1.首先解释下,启动mysql时为何会调用mysql_safe脚本来启动mysql [root@localhost ~]# /etc/init.d/mysqld start 正在启动 mysqld: ...

  6. JAVA练习

    JAVA基础练习 1.给java,stb,sql三门科目的成绩算出JAVA和SQL的成绩差,JAVA和SQL的成绩共是,三门课的总分是,三门课的平均分是多少 import java.util.Scan ...

  7. Working with BeforeProperties and AfterProperties on SPItemEventReceiver

    As many of you know, event receivers are a great way to hook into various SharePoint events.  These ...

  8. YII数据库操作(CURD操作)

    数据库操作 获得模型对象 $model = 模型名::model();或$model = new 模型名(); 1.查询多条记录(返回值:二维数组) $result = $model->find ...

  9. UVA 11732 strcmp() Anyone?(Trie的性质)

    strcmp() Anyone? strcmp() is a library function in C/C++ which compares two strings. It takes two st ...

  10. VS中使用sqlite静态连接

    说明 最近写的文章有些多,懒得打字了,就直接上文章.这里说明一下,我说的是VS,不是指定的哪一个VS版本.先下载官方的源文件:sqlite-amalgamation-3071502.zip 下载下来的 ...