1 solutions
-
0
C :
#include <stdio.h> int main() { int n1,n2,num,i,step; while(scanf("%d%d",&n1,&n2)!=EOF) { num=n2-n1; i=1; step=0; if(num==0) printf("%d\n",num); else while(1) { num-=i; step++; if(num<=0) { printf("%d\n",step); break; } num-=i; step++; if(num<=0) { printf("%d\n",step); break; } i++; } } return 0; }C++ :
#include <bits/stdc++.h> using namespace std; int main() { long long x1,x2; while(~scanf("%lld%lld",&x1,&x2)){ long long cha=x2-x1; long long step=0; if (cha==0){ printf("0\n"); continue; } while((step*step)<=cha){ step++; } /* prlong longf("%lld\n",step*0); prlong longf("%lld\n",step*1); prlong longf("%lld\n",step*2); */ if (cha- (step*step) >=0){ cha -= (step*step); } else{ step--; cha -= (step*step); } if (cha==0){ printf("%lld\n",step*2-1); continue; } long long ans=step; if (cha%step>0){ ans+=((cha/step)+1); } else ans+=(cha/step); if (step>1) ans+=step-1; printf("%lld\n",ans); } return 0; }
- 1
Information
- ID
- 18238
- Time
- 2000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By