JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Another Game With Numbers http://www.spoj.com/problems/NGM2/ | Reply
Hi I am new to this Topcoder Please help me

I am submitting a solution on SPOJ of 6285. Another Game With Numbers
I am geting run time error on spoj after running 25 test cases

here is my code

#include<stdio.h>
int main()
{
long long int N,K,NUM[1000000],MTH[100],i,j,count=0,count2=0,x;
scanf("%lld %lld",&N,&K);

for(i=0;i<K;i++)
scanf("%lld",&MTH[i]);

for(i=1;i<=N;i++)
NUM[i]=i;

for(j=0;j<K;j++)
{
for(x=1,i=MTH[j],x<(N/MTH[j]);i<N;i++,x++)
{
if((MTH[j]*x) == NUM[(MTH[j])*x]||x><(N/MTH[j]))
NUM[MTH[j]*x]=0;
}
}
for(i=1;i<N;i++)
{
if(NUM[i]==0)
count++;
else
count2++;
//printf("%lld ",NUM[i]);
}//printf("\n");
printf("%lld",count2);
return 0;
}

here I am putting the value 0 of all multiples of the given second K numbers and then counting the non zero numbers and printing it out.

my code is giving correct solution but spoj is showing runtime error after running 25 test cases.>
RSS