You are not logged in. Please login at www.codechef.com to post your questions!

×

Help to solve Minimum Deletion RD19

0
1

Hi there, I am new in this forum, so please help me with your suggestions.. Earlier today I was trying to solve the problem under "Practice>Beginner" named "Minimum Deletion" tag:RD19 I know it's a smart way to solve this by finding GCD of the numbers but I tried something else. The GCD of the numbers suppose to be 1 if all of them are PRIME numbers, so we just wanna know how many numbers are not prime in the given nembers.. So I write the code which is looking fine to me but after submission it says "Wrong answer" I will appreciate if someone help me to find the bug in my code...

//RD19
//Unsolved
#include<stdio.h>
#include<math.h>
int test_case(int ara[], int b);
int main()
{
    int a,b,d,e;
    int i,j;
    int x,y;
    scanf("%d",&a);
    for(j=0;j<a;j++)
    {
        scanf("%d",&b);
        int ara[b];
        for(i=0;i<b;i++)
        {
            scanf("%d",&ara[i]);
        }
            x=test_case(ara,b);
    if(x==1)
    {
        x=-1;
        printf("%d\n",x);
    }
    else
    {
    printf("%d\n",x);
    }
    }
    return 0;
}
int test_case(int ara[], int b)
{
    int i,j,k=0,x=0,y; 
    for(i=0;i<b;i++)
    {
        if(ara[i]==1||ara[i]==2)
        {
            x=0;
        }
        else if(ara[i]%2==0)
        {
            x=1;
        }
        y=sqrt(ara[i]);
        for(j=3;j<=y;j=j+2)
        {
            if(ara[i]%j==0)
            {
                x=1;
            }

        }
        if(x==1)
        {
            k=k+1;
        }
    }
    return k;   
}

asked 12 Jun, 22:01

hs_santo's gravatar image

0★hs_santo
32
accept rate: 0%

edited 12 Jun, 22:06


Consider the test case 6, 8, 9 the answer should be 0 as you don’t need to delete any numbers to achieve a GCD of 1 altogether. So this is the case of all numbers being Coprime.

link

answered 13 Jun, 21:36

kool's gravatar image

2★kool
661
accept rate: 100%

Thank you so much for your help....

(13 Jun, 22:19) hs_santo0★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,359
×15
×6
×1

question asked: 12 Jun, 22:01

question was seen: 59 times

last updated: 13 Jun, 22:19