bzoj3858Number Transformation*

bzoj3858Number Transformation

题意:

给一个数n,对其进行k次变换,第i次变换是将当前的n变成大于等于n的最小的i的倍数。求k次变换后n为多少。n≤10^10,k≤10^10。

题解:

对n的变换可以表示成ceil(n/i)*i。有一个结论,当i第一次大于sqrt(当前的n)后,以后的i将永远大于sqrt(那时的n),且从这以后ceil(n/i)都相等。因此可以先暴力变换n,当i大于sqrt(当前n)后,求出ceil(n/i),直接乘k就是最后答案。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <cmath>
 5 #define inc(i,j,k) for(int i=j;i<=k;i++)
 6 #define ll long long
 7 using namespace std;
 8 
 9 inline ll read(){
10     char ch=getchar(); ll f=1,x=0;
11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
12     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
13     return f*x;
14 }
15 ll n,k; int t;
16 int main(){
17     while(1){
18         n=read(); k=read(); if(n==0&&k==0)break; t++; int i;
19         for(i=1;i<=k&&i<=(int)sqrt(n)+1;i++)n=(n+i-1)/i*i;
20         if(i==k+1)printf("Case #%d: %lld\n",t,n);
21         else{n/=(i-1); printf("Case #%d: %lld\n",t,n*k);}
22     }
23     return 0;
24 }

 

20160812

转载于:https://www.cnblogs.com/YuanZiming/p/5776322.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值