|
|
back to boardc++ code always wrong in test #3, anyone who get accepted could help me? #include <iostream> #include <cmath> bool isOne (long n) { double intPart; double para = (1 + sqrt ( 8 * n -7)) / 2; double fractPart = modf(para, &intPart); if (fractPart == 0.0) return true; else return false; } int main() { using namespace std; long value; long num, i = 0;
cin >> num; while (i < num) { cin >> value; if (isOne (value)) cout << "1 "; else cout << "0 "; i++; } return 0; } Re: c++ code always wrong in test #3, anyone who get accepted could help me? Posted by junior 9 Dec 2013 08:12 Think about how big can be 8 * n. Re: c++ code always wrong in test #3, anyone who get accepted could help me? Posted by Sawyer5 17 Jun 2014 00:22 accepted if you use long long instead long |
|
|