ALEXTASK - Editorial

Can someone please point out what i have done wrong in this code?

@sourav0457 you are missing a couple of things, new line after each test case, fin is not long long int, second loop in which you are finding minimum will have j< index not j<=index, and a return statement at the end of program.

your solution of after these corrections link.

@srd091 thankyou :slight_smile:

1 Like

Can anybody explain why this code in C++ produces AC to task # 3 and #4 but WA for other tasks?

1 Like

@ravibitsgoa You have to find lcm of all pairs , but you have done it only for the least two no which is be incorrect. For example try this test case

1

3

4 5 6

Your code will output 20 (lcm of 4 and 5) , but answer should be 12 (lcm of 4 and 6).

Check my solution for this link text

I have a doubt, Cant we just sort the array and take the lcm of the first 2 elements (smallest 2 elements) ? Doesnt that produce a correct answer ?

For C++ users…

You guys can easily use inbuilt __gcd(… , …) to avoid hustle in writing all code of gcd() externally!

1 Like

@chari407 no it will be wrong.

try this test case

1

3

4 5 6

As per your algo o/p will be 20(lcm of 4,5) but it should be 12 (lcm of 4,6)

Check my solution for this link text

Can anyone tell why I am getting wrong answer on task 2. I am applying the same method as provided in editorial. Here is the link.

@d1k5 using double variables - very bad idea. Your solution was good, but if you use long long to calculate LCA, a[i] and a[j] must be long long too

Can anyone please tell what I have done wrong in this code in Java.

Thank You

can someone plz point out whats wrong in my


[1]?


  [1]: https://www.codechef.com/viewsolution/12045932

can anybody tell me why this code gives WA for the last testcase ?

thank you…

Can somebody help me solve why this solution is wrong,


[1]
This code works for most cases but don't know for which it is failing. This code works in O(N).

Below are the test cases that i tested, ( which passed successfully )

    10
    10 2 3 10 4 5 4 3 3 4
    
    6
    3 4 5 4 4 3
    
    3
    2 3 5
    
    4
    1 8 7 11
    
    4
    4 4 5 6
    
    10
    1 3 4 2 6 7 10 44 1 2
    
    10
    10 2 3 10 4 5 4 3 3 4
    
    10
    1 3 4 2 6 7 10 44 1 2
    
    7
    58 59 100 10266 6844 10000 1000000
    
    4
    1000000000 1000000000 999999999 999999222
    
    5
    1000000000 2000000000 989898989 878787878
    
    2
    1 1
    
    2
    4 1


  [1]: https://www.codechef.com/viewsolution/12399435

can anyone explain task… actually i am not getting it

what are u not getting

@soni_singh

rather than checking every possibility we should lake the LCM of two smallest numbers in the array the should check for only those pair which in which element are then the LCM of smallest
for EXAMPLE

we have an array say

3,3498,45,435,656,67,4,10,5

we sort it

3,4,5,10,45,67,435,656,3498

then we took LCM OF 3 & 4 which is 12 and check for only those element which are less than 12

Hi all,
I have tried the same logic first sorted the list ,
If there is ‘1’ in the array then the next element is the result.
Otherwise fining any similar elements , as the list is sorted the first such element is taken.
Then the lcm is taken between first element and rest of the array and min of that is returned.
Then depending on which is the lesser one, the result is calculate.
The code is here . what is it I am doing wrong?

My python code passes all tasks except the last one for large numbers. Can somebody tell me what I can do?

from fractions import gcd
def lcm(a,b):
return (a*b)/gcd(a,b)
t=int(input() )
while t:
t=t-1
n=int(input())
l=map(int,raw_input().split(" "))
min1 =[]
for i in range(len(l)):
for j in range(i+1,len(l)):
val = lcm(l[i],l[j])
min1.append(val)
min1.sort()
print min1[0]

I am getting NZEC for the last task, what is the problem here ? Thank you.