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 WA in test 2. My code here. Please help me.
Posted by nguyenductam 5 Apr 2010 10:15
#include<stdio.h>
 #include<conio.h>


long int i,j,n,m,aa,bb,cc,lap,k,l;
int a[50001],sont;
int dem[50001];
long int kq;

void InitPrime();
long int Max(long int x,long int y);
long int Min(long int x,long int y);
void InitDem();
void Test();

int main()
{
    scanf("%ld %ld",&n,&m);
    aa=Max(n,m);
    bb=Min(n,m);
    cc=aa-bb;

    InitDem();
    InitPrime();
 //   Test();

    lap=Max(bb,cc);
    i=lap+1;
    // tinh so nguyen to o tren tu
    while(i<=aa)
    {
           k=0;
           l=i;
           while(l!=1)
           {
            k++;
            while((l%a[k])==0)
            {
             l=l/a[k];
             dem[a[k]]++;
            }
           }
           i++;
    }

    // tinh so nguyen to duoi mau
    lap=Min(bb,cc);
    i=2;
    // tinh so nguyen to o tren tu
    while(i<=lap)
    {
           k=0;
           l=i;
           while(l!=1)
           {
            k++;
            while((l%a[k])==0)
            {
             l=l/a[k];
             dem[a[k]]--;
            }
           }
           i++;
    }

    //dem ket qua
    kq=0;
    i=2;
    while(i<=aa)
    {
     if(dem[i]!=0) kq+=dem[i];
     i++;
    }
    printf("%ld",kq);

    getch();
    return 0;
}

void InitDem()
{
 i=1;
 while(i<=aa)
 {
  dem[i]=0;
  i++;
 }
}

long int Max(long int x,long int y)
{
 if(x<=y) return y;
 return x;
}

long int Min(long int x,long int y)
{
 if(x<=y) return x;
 return y;
}

void InitPrime()
{
     int flag;
     long int x;
     a[1]=2;
     a[2]=3;
     a[3]=5;
     a[4]=7;
     i=4;
     x=11;
     while(x<aa+1)
     {
                   j=2;
                   flag=1;
                   while(j*j<x)
                   {
                    if(x%j==0)
                    {
                     flag=0;
                     break;
                    }
                    j++;
                   }
                   if(flag==1)
                   {
                     a[++i]=x;
                   }
                   x+=2;
     }
     sont=i;
}
void Test()
{
 for(i=1;i<=sont;i++) printf("%d\n",a[i]);
// getch();
}
Re: Why WA in test 2. My code here. Please help me.
Posted by Varun Sharma 6 Apr 2010 14:23
Hi,

Try these test cases:

Test Cases

200000 40000
9011

100000 35000
6109

123456 12345
3892

987654 98765
25861

560011 12000
5255

340999 43560
11372

235000 34001
8723

89340 10000
3123

98112 23
35

4567 456
212

Varun
Re: Why WA in test 2. My code here. Please help me.
Posted by TheDreamCatcher 1 Dec 2010 13:47
Varun Sharma wrote 6 April 2010 14:23
Hi,

Try these test cases:

Test Cases

200000 40000
9011

100000 35000
6109

123456 12345
3892

987654 98765
25861

560011 12000
5255

340999 43560
11372

235000 34001
8723

89340 10000
3123

98112 23
35

4567 456
212

Varun

N M between 1 & 50 000