想用除过一下,求k为2的倍数的处理方法

P1150 Peter 的烟

Artorius @ 2019-11-21 10:36:20

#include<stdio.h>

int main()

{
 int n,k,sum=0,c=0;
scanf("%d %d",&n,&k);

 if(k>1&&n>1)
{ 
    sum=n;
while(n>k)
{  

    n=(n+c)/k;
    c=n%k;
    sum+=n;
}
 printf("%d",sum);
}
 return 0;
}

by Artorius @ 2019-11-21 11:00:44

=。= 求处理 10 3和 10 2


by jack070906 @ 2020-04-05 16:03:54

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k,s=0;
    cin>>n>>k;
    while (n>=k)
    {
        s+=k;
        n=n-k+1;
    }
    cout<<s+n;
    return 0;
}

你那样太麻烦了


|