ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

c++ code always wrong in test #3, anyone who get accepted could help me?
Posted by WENXIANG LU 8 Nov 2013 22:07
#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