why?第三点错了,求大佬帮忙,感激不尽

P1150 Peter 的烟

lcf3241142097 @ 2017-10-06 16:00:01

var
        n,k,i,ans,max:int64;
begin
        readln(n,k);
        ans:=n;
        repeat
                ans:=ans div k;
                max:=max+ans;
        until ans<k;
        writeln(n+max);
end.

by 市场花园行动 @ 2017-10-06 21:44:48

#include<iostream>
using namespace std;
int main()
{
    int n,k,s;
    cin>>n>>k;
    s=n;
     while(n>=k)
     {
         n=n-k;
         n=n+1;
         s=s+1;
     }
    cout<<s<<endl;
    return 0;
}

by 市场花园行动 @ 2017-10-06 21:45:18

额,是c++的,不好意思....


by ljxljxljx @ 2017-10-08 20:26:13

var
n,k,sum:longint;
begin
  read(n,k);
  sum:=n;
  while sum=sum do
    begin
      n:=n-k+1;
      inc(sum);
      if n<k then break;
    end;
  write(sum);
end.

by ljxljxljx @ 2017-10-08 20:26:55

用减法,慢慢来。


by bh1234666 @ 2017-11-24 20:15:45

@lcf3241142097 小心边缘数据

这个是w#3的代码

#include<cstdio>
using namespace std;
int main()
{
    int n,k,count,countt;
    scanf("%d%d",&n,&k);
    count=n;
    countt=n;
    while(countt>k)
    {
        countt-=k;
        countt++;
        count++;
    }
    printf("%d",count);
    return 0;
}
countt>k改成countt>=k就A了

|