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

why? I got the "Compilation error!"
Posted by Ray's Try 26 Apr 2007 09:11
#include<stdio.h>
#include<math.h>
#include<string.h>

long n,m,p,i;
int j;
double ab;
int a[50010];

void divide1(long t)
{
     for (j=2;j<sqrt(t);j++)
     {
          while (t % j == 0)
          {
               if (a[j]==0) p++;
               a[j]++;
               t/=j;
          }
     }
     if (t>1)
       {
           if (a[t]==0) p++;
           a[t]++;
       }
}

void divide2(long t)
{
     for (j=2;j<sqrt(t);j++)
     {
         while (t % j == 0)
          {
               a[j]--;
               if (a[j]==0) p--;
               t/=j;
          }
     }
     if (t>1)
       {
           a[t]--;
           if (a[t]==0) p--;
       }

}

int main()
{
    scanf("%ld %ld", &n, &m);
    if (n - m < m) m = n-m;
    memset(a,0,sizeof(a));
    for (i=n;i>=n-m+1;i--)
    {
        divide1(i);
    }
    for (i=1;i<=m;i++)
    {
        divide2(i);
    }
    printf("%ld\n", p);
    return 0;
}
Re: why? I got the "Compilation error!"
Posted by Todor Tsonkov 26 Apr 2007 14:27
you use long t and sqrt(t) and t must be double e.g. use sqrt(double(t) ). btw, you get WA6 after I submitted yr code

Edited by author 26.04.2007 14:29