#include <stdio.h>
#include <stdlib.h>
int main()
{ int n;
while(scanf("%d",&n)!=EOF){
int m;
scanf("%d",&m);
int sum ;
int j=0;
sum = 0;
while(sum<=m){
sum = sum +n;
n++;
j++;
}
printf("%d\n",j);
}
return 0;
}
#include
#include
int main()
{ int n;
while(scanf("%d",&n)!=EOF){
int m;
scanf("%d",&m);
int sum ;
int j=0;
sum = 0;
while(sum<=m){
sum = sum +n;
n++;
j++;
}
printf("%d\n",j);
}
return 0;
}
應該是int溢位了
用long long int 試試看
#include
#include
int main()
{ int n;
while(scanf("%d",&n)!=EOF){
int m;
scanf("%d",&m);
int sum ;
int j=0;
sum = 0;
while(sum<=m){
sum = sum +n;
n++;
j++;
}
printf("%d\n",j);
}
return 0;
}
應該是int溢位了
用long long int 試試看
如果不是,應該就是https://zerojudge.tw/ShowThread?postid=11685&reply=7002#11685的問題了
反正以下的程式碼是可以AC的(盡量自己寫吧,不會再看):
#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { long long int n,m,i; while(cin>>n>>m){ long long int b=0,c=0; for(int i=n; ;i++) { b=b+i; c++; if(b>m) break; }cout<<c<<endl; } }