BZOJ3858: Number Transformation

时间:2023-06-14 17:17:42

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3858

题解:设第i个数为i*a;第i+1个数为(i+1)*b。则(i+1)*b>i*a;b>a-(a/(i+1));那么如果a<i+1;b的值就会不变

此时k*b就为所求;而由于a在不断的变小,a<i+1;在数值比较大的情况下就能实现
这么乱搞都行?!
代码:
 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 200000+5

 #define maxm 200000+5

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)

 #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)

 #define mod 1000000007

 using namespace std;

 inline int read()

 {

     int x=,f=;char ch=getchar();

     while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}

     while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}

     return x*f;

 }

 int main()

 {

     freopen("input.txt","r",stdin);

     freopen("output.txt","w",stdout);
ll n,m;int cs=; while(scanf("%lld%lld",&n,&m)&&(n||m))
{
ll i,j;
for(i=;i<=m;i++)
{
j=n/i+(n%i>);
if(j<i+)break;
n=j*i;
}
if(i<=m)n=j*m;
printf("Case #%d: %lld\n",++cs,n);
} return ; }