/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'll f(ll)':
/in/foo.cc:22:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 状态 耗时 内存占用
#1 Accepted 3ms 384.0 KiB
#2 Accepted 3ms 348.0 KiB
#3 Accepted 3ms 356.0 KiB
#4 Accepted 3ms 376.0 KiB
#5 Accepted 3ms 348.0 KiB
#6 Accepted 3ms 384.0 KiB
#7 Accepted 3ms 368.0 KiB
#8 Accepted 3ms 364.0 KiB
#9 Accepted 3ms 356.0 KiB
#10 Accepted 3ms 364.0 KiB

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,l=0,r=0x7fffffff,mid,temp;
ll f(ll n)
{
	while(l!=r)
	{
		mid=(l+r)/2;
		//cout<<"l="<<l<<" r="<<r<<" mid="<<mid;
		temp=mid*mid;
		//cout<<" temp="<<temp<<endl;
		if(temp==n)
		{
			cout<<mid*2-1;
			exit(0);
		}
		else if(temp>n)
		r=mid;
		else l=mid+1;
	}
}
int main()
{
	cin>>n;
	f(n);
	ll s=n-l*l;
	if(s>0)
	{
		if(s>=l) cout<<2*l;
		else cout<<2*l-1;
	}
	else if(s==0)
	cout<<2*l-1;
	else {
		if(-s<=l) cout<<2*l-2;
		else cout<<2*l-3;
	}
	return 0;
	
}

信息

递交者
类型
递交
题目
整除 T2
题目数据
下载
语言
C++
递交时间
2017-10-13 08:59:41
评测时间
2017-10-13 08:59:41
评测机
分数
100
总耗时
34ms
峰值内存
384.0 KiB