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

where is wrong?Help me,please!
Posted by csyzcyj 22 Feb 2013 15:08
My program(LANG c)is in the following:
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
int k[60000],value,i,n;
int main()
{
    scanf("%d",&n);
    for(i=1;i<=n;i++)
       scanf("%d",&k[i]);
    for(i=1;i<=n;i++)
    {
         if(k[i]==0) printf("0 ");
         else
         {
              value=(int)sqrt((k[i]-1)*2);
              if((value*(value+1))==2*(k[i]-1))
                 if(i==n)  printf("1\n");
                 else printf("1 ");
              else
                 if(i==n) printf("0\n");
                 else printf("0 ");
              }
    }
    return 0;
}

BUT it can't compile,said that
"
d9b0f699-b537-45eb-b286-ce7765096c87d9b0f699-b537-45eb-b286-ce7765096c87(16) : error C2668: 'sqrt' : ambiguous call to overloaded functionS:\checker\compile\vc10\include\math.h(589): could be 'long double sqrt(long double)' S:\checker\compile\vc10\include\math.h(541): or 'float sqrt(float)' S:\checker\compile\vc10\include\math.h(127): or 'double sqrt(double)' while trying to match the argument list '(int)'
"

BUT in my computer(Windows 7),I can compile and run it,and the answer is right.
So I don't know where is wrong?And I don't know how to modify it.Help me,please!

Edited by author 22.02.2013 15:09
Re: where is wrong?Help me,please!
Posted by nubpun 20 Mar 2013 21:20
length array int k[65535]
becouse
(1 ≤ N ≤ 65535)
Re: where is wrong?Help me,please!
Posted by daria 25 Mar 2013 20:13
csyzcyj wrote 22 February 2013 15:08
My program(LANG c)is in the following:
...................
int k[60000],value,i,n;
...................
              value=(int)sqrt((k[i]-1)*2);    //  sqrt(double((k[i]-1)*2))
...................
Edited by author 22.02.2013 15:09
your wrong is use (int) with sqrt.
template for SQRT is   sqrt(double).
you must to give for sqrt double variable, and if you need int variable, you must to appropriate value in int variable. Signs after a comma will be removed.
I am sorry for my bad English.

Edited by author 25.03.2013 20:14