LEDIV - Editorial

if we check the array elements by dividing with the prime numbers upto the square root of maximum element of the array.

following this i got WA, can you please give flaw in this approach.

my submission id 1565051

1 Like

http://www.codechef.com/viewsolution/1565258

@admin where is my code failing?

An alternative solution, maybe one that is slightly easier to understand, would be to find all the divisors of the first number, then try each of these divisors on all others numbers and check if they are divisible by it also.

1 Like

http://www.codechef.com/viewsolution/1565594

@admin : Can u tell for which cases it is generating wrong anwers ?

#include<stdio.h>
#include<math.h>
long p[1000],y[100005]={0},x[100005];
void sieve()
{
long i,j;
for(i=3;i<=316;i+=2)
if(y[i]==0)
for(j=i*i;j<=100000;j+=i+i)
y[j]=1;
p[0]=2;
j=0;
for(i=3;i<=100000;i+=2)
if(y[i]==0)
p[++j]=i;
}
int main()
{
long t,n,i,j;
sieve();
scanf("%ld",&t);
while(t–)
{
scanf("%ld",&n);
long min=10000000,f=1;
for(i=0;i<n;++i)
{
scanf("%ld",&x[i]);
if(min>x[i])
min=x[i];
}
for(i=0;p[i]<=min;++i)
{
for(j=0;j<n;++j)
if(x[j]%p[i])
break;
if(j==n)
{
printf("%ld\n",p[i]);
f=0;
break;
}
}
if(f)
printf("-1\n");
}
return 0;

}

i know this approach is not good but i want to know the mistake i made.please reply.thanks in advance.

http://www.codechef.com/viewsolution/1565687
i should get TLE…but getting WA .just want to know which test case solution fails…

i used the same method as given in this editorial but still getting TLE plzz can anyone tell me why i m getting TLE
http://www.codechef.com/viewsolution/1641999

When T and N are constrained to 100000, how come the tester’s solution pass with data type “int” used?

CodeChef: Practical coding for everyone What’s wrong in my code? It shows WA. I’ve implemented the method shown in the editorial. Please help.

i am getting a WA…
please help…

#include<stdio.h>
long int a[100000]={0};
int main(void)
{
 long int t,n,i,min,flag,j,res;
 min=100000;
 scanf("%ld",&t);
 while(t--)
 {
  scanf("%ld",&n);
  for(i=0;i<n;i++)
  {
   scanf("%ld",&a[i]);
   if(a[i]<min)
   {
    min=a[i];
   }
  }
  for(i=2;i<=min;i++)
  {
   flag=1;
   for(j=0;j<n;j++)
   {
    if(a[j]%i!=0)
    {
     flag=0;
     break;
    }
   }
   if(flag==1)
   {
    res=i;
    break;
   }
  }
  if(flag==0)
  {
   res=-1;
  }
  printf("%ld\n",res);
 }
 return 0;
}

i am getting a WA… please help…

#include<stdio.h>
int main(void)
{
 int t,ds,dt,d,x;
 x=0;
 scanf("%d",&t);
 while(t--)
 {
  scanf("%d%d%d",&ds,&dt,&d);
  if(ds+dt<d)
  {
   printf("%.6f\n",(float)(d-dt-ds));
  }
  else
  {
   printf("%.6f\n",(float)(x));
  }
 }
 return 0;
}

https://www.codechef.com/viewsolution/13098242
can somebody tell me, for which case it is not working???

I am getting WA.Please tell me the case where my code fails.
https://www.codechef.com/viewsolution/14322036

I am getting wrong answer although in the dry run everything seems to be working fine. Also, the sample test cases from editorial are working.

Can anyone suggest the test case which could fail my solution/ review my solution?

https://www.codechef.com/viewsolution/14364283

TestCases:

1 1 1 => -1 (since x>1)

1 2 20122 30183 => 10061

1 1 24371 => 24371

1 2 123 456 => 3

Many Thanks!

When your ‘r’ is divisible by 3 you did not find this. Say r=63.

1 Like

That was a huge miss … sorry . .
but sadly that does not fix the error
submission 1565280

Consider T=1 N=1 A[1]=24371

2 Likes

You logic is completely incorrect. Try this test T=1 N=2 A[1] = 2 * P A[2] = 3 * P where P is large prime say A[1] = 20122, A[2] = 30183.

1 Like

Try the simplest possible test:
1
1
1
:wink:

3 Likes

well … lesson learned …paid for incoherence. .
@anton thank a lot , very much appreciated :slight_smile: