开始补一波blog。(这几天都做无码量的题?233)
这道题师兄出过给我们做,记得当时挺懵逼的。。。
规律确实可找,>=sqrt(n)之后向上取整就不变了,这个可以列不等式证一下.
复杂度的话,考虑每次最多增加i-1就好,所以还是
n√
级别的
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
char O[1<<14],*S=O,*T=O;
#define gc (S==T&&(T=(S=O)+fread(O,1,1<<14,stdin),S==T)?-1:*S++)
inline LL read(){
LL x=0,f=1; char ch=gc;
while(ch<'0' || ch>'9'){if(ch=='-')f=-1; ch=gc;}
while(ch>='0' && ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=gc;}
return x*f;
}
int main(){
int t=0;
while(1){
LL n=read(),k=read(); if(!n)break;
for(LL i=2;i<=k;++i){
if(i*i>=n){n=(n+i-1)/i*k; break;}
n=(n+i-1)/i*i;
}
printf("Case #%d: %lld\n",++t,n);
}
return 0;
}