1 条题解

  • 0
    @ 2024-12-22 11:04:50

    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;
    }
    

    信息

    ID
    414
    时间
    2000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者