#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long x,ans;
while(cin>>x)
{
ans=(-1+(long long)sqrt(1+8*x))/2;
cout<<ans<<endl;
}
}
2147483647 這組答案不知道如何通過 求解
#include
#include
using namespace std;
int main()
{
long long x,ans;
while(cin>>x)
{
ans=(-1+(long long)sqrt(1+8*x))/2;
cout<<ans<<endl;
}
}
2147483647 這組答案不知道如何通過 求解
好像運算中有溢位喔0u0
運算中用double
輸出的時候再用long long 就 ok 了
#include <iostream> #include <math.h> using namespace std; int main() { long long x; while(cin >> x) { double d = (sqrt(1 + 8.0 * x) - 1) / 2.0; long long ans = d; cout << ans << endl; } }
// 小修