CLLCM EDITORIAL

You need to find (check if exist) an odd number x which is divisible by all array elements not all array elements divided by x. Hope it is clear to you now.

1 Like

" So if all numbers are odd then the answer will be “ YES ”, otherwise “ NO ” "
What if all the numbers are odd prime ?? Then any number can’t be divisible by all the other numbers…
Test Case:
3
3 5 7

The odd no. should be divisible by them.
Read Problem carefully.

But in question they said that the number X should be present in N numbers which chef have ?
In your example 105 is not in the number list ?
Please explain .

i too tried the same approach

I wrote about the logic. Hope it’ll help you. :slight_smile:

What’s wrong with my code.?? I used the logic if there is even num present print NO else print YES

#include< iostream >
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int n,f=0;
        cin>>n;
        int arr[1000];

        for(int j=0;j<n;j++)
        cin>>arr[j];

        for(int j=0;j<n;j++)
        {
        if(arr[j]%2==0)
        {
            cout<<"NO"<<endl;
            f=1;
            break;
        }
        }
        if(f==0)
        cout<<"YES";
    }

    return 0;
}

See your output is not matching the way they wanted.

if(f==0)
{
    cout<<"YES\n";
}

try this once.

I too used the same technique. didn’t get the glitch

still didn’t worked

I’ve added C++14 program. Please check that & if any problem is still persists drop an email (falgunisarkar526@gmail.com). :mask:

one of the number is 105 .
because 3 * 5 * 7 = 105.
odd * odd = odd

I guess for a few big prime numbers in range 1-1000 the LCM would end up being the multiplication of those numbers and eventually overflow the 64 bit integer type which I naively thought was enough for the problem :sweat_smile: Lesson learned.

why this code gives wrong answer?
instead of scanf if I use cin then it gives ac. why?

YES, i got it from this .

Many people done using LCM because the problem name is “CLCM” LOL

Two interesting coder's legacy 2020 problems for beginners 🔥🔥 - Flying concepts of C.P. - YouTube Solution video of this “first” and second question of coder’s legacy 2020

what if I use long long int, will it still overflow?

Yes, it will. Let’s think if I give you at least ~20 prime number then their lcm will overflow for sure.

Can you please specify some primes under these constraints, which cause integer flow? I’m surprised to see.