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...

It accepted!!!
Posted by ScaleS 17 Mar 2009 13:52
It accepted!!!
Posted by ScaleS 17 Mar 2009 13:53
var
  n,i : word;
  p : real;

function check(A : real):boolean;
begin
  if frac((1+sqrt(8*A-7))/2) = 0.0 then check := true else check:=false;
end;

begin
  readln(n);
  for i:=1 to n do
  begin
    readln(p);
    if check(p) then write('1 ')
    else write('0 ');
  end;
end.
Re: It accepted!!!
Posted by Flamer.contest 12 Mar 2010 16:34
Yes, because the difference of correct answer (when you use -1) and your is 2, so there is no difference to use +1 or -1! ))))
Re: It accepted!!!
Posted by zAlogic 16 Dec 2010 15:20
 frac((1+sqrt(8*A-7))/2)

Where from it  formula? What means?
Re: It accepted!!!
Posted by WENXIANG LU 8 Nov 2013 22:25
Could you take a look at my c++ code? I did the same as you but i never pass test #3 !!

#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;
}