「BZOJ1349」[Baltic2006] Squint
Description
Write a program to calculate integer square roots.
Input
The input is read from a text file named squint.in. Its only line consists of an integer 0 < = n < 2^63 .
Output
Its only line consists of the smallest nonnegative integer q such that q^2 >= n .
Sample Input
122333444455555
Sample Output
11060446
HINT
sqrt(122333444455555)=11060445.038765619 .
题解
直接sqrt(n) 真是神题啊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define ll long long #define inf 1000000000 using namespace std; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ll n,ans; int main() { n=read(); ans=sqrt(n); if(ans*ans!=n)ans++; printf("%lld",ans); return 0; } |
Subscribe