1 条题解
-
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
信息
- ID
- 3528
- 时间
- 2000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者