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进阶——安卓接入微信,获取OpenID

    PS: sendAuthRequest拿到code,通过code拿到access_token和openId,access_token可以拿到用户的信息 http://blog.csdn.net/hao ...

  2. Cisco 交换机与路由器故障处理方法分享

    一.网络的复杂性 一般网络包括路由.拨号.交换.视频.WAN(ISDN.帧中继.ATM.…).LAN.VLAN.… 二.故障处理模型 1. 界定问题(Define the Problem) 详细而精确 ...

  3. 利用Qt调用计算器

    之前有了第一个项目那么很快就会有第二个 这次 我们来调用 一些系统函数. 就不从头写了. 直接写比较重要的地方,如果又不太懂的地方欢迎小纸条或者参见利用 QT制作一个 helloworld http: ...

  4. [转]Form中控制Tab画布不同标签间切换的方法

    转自:http://yedward.net/?id=68 Form中一般常用的画布类型包括content.stacked.tab这三种,其实content类型的画布是每一个form都必须有的,而且只能 ...

  5. 初见Javascript

    1.HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 <body> 和 <head> ...

  6. HeaderViewListAdapter cannot be cast to listAdapter问题原因及解决办法

    [o] 在listView中添加leaderView 和footerView的时候要注意在setAdapter之前调用,不然会报如下异常: listAdapter cannot be cast to ...

  7. MFC对话框程序EDIT类控件的自动换行,垂直滚动条自动下移

    1.新建一个Edit Control,将其Multiline属性设置为True,Auto HScroll属性设置False,这样就可以实现每一行填满后自动换行了.   2.再将Vetrical Scr ...

  8. Android TabHost的使用

    标签显示界面的主要特点是可以在一个窗口中显示多组标签栏的类容. 在Android系统中,每个标签栏称为一个Tab,而包含多个标签栏的内容就称为TabHost. 通过TabHost的继承结构来看,Tab ...

  9. .NET Entity Framework入门简介及简单操作

    Entity Framework是微软借鉴ORM思想开发自己的一个ORM框架. ORM就是将数据库表与实体对象(相当于三层中的Model类)相互映射的一种思想. 最大的优点就是非常方便的跨数据库平台. ...

  10. OC - 4.OC核心语法

    一.点语法 1> 基本使用 点语法本质上是set方法/get方法的调用 2> 使用注意 若出现在赋值操作符的右边,在执行时会转换成get方法 若出现在赋值操作符的左边,在执行时会转换成se ...