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

Why Compilation error?-- Help me,Thank you.
Posted by youngtrips 2 Oct 2007 13:10
#include <cstdio>
#include <cmath>
#include <memory>
const int MAX = 170001;
bool prime[MAX];
int p[15001];
void findPrime()
{
     int i,j;
     memset(prime,true,sizeof(prime));
     //for(i = 0;i <MAX; i++)
       //    prime[i] = true;
     for(i = 2;i < sqrt(MAX);)
     {
           if(prime[i] == true)
                 for(j = i * i;j < MAX; j += i)
                       prime[j] = false;
           if(i == 2)
              i++;
           else
              i += 2;
     }
}
int main()
{
    findPrime();
    int i,k,j;
    j = 1;
    for(i = 2;i < MAX; i++)
    {
          if(prime[i])
                      p[j++] = i;
    }
    scanf("%d",&k);
    while(k--)
    {
              scanf("%d",&i);
              printf("%d\n",p[i]);
    }
    return 0;
}
Re: Why Compilation error?-- Help me,Thank you.
Posted by youngtrips 2 Oct 2007 13:16
I got it.
In the FAQ,it says that,
In C/C++ you cannot call functions from header math.h with integer parameters. This code will not be compiled: sqrt(2). You can write correctly sqrt((double)2) or sqrt(2.0).