Code Hunt
Practice
0 (0 votes)
Medium
Number theory
Greatest common divisor
Algorithms
Mathematics
Open
Approved
Problem
4% Success 1129 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Little Stuart has reached the final level of 'Code Hunt', the annual treasure hunt organised by HackerEarth. Now for the final level, Little Stuart has to choose a door from infinite number of doors numbered from 1 to infinity. Out of these only one door contains the grand prize. The clue for finding the correct door is as follows

Your task is to help Little Stuart find the correct door, so that he can win.

DoorNumber=0

for (i=0;i<ArraySize-1;i++)

  for(j=i+1;j<ArraySize;j++)

       if(GCD(a[i],a[j])==a[j])

             if(GCD(2^a[i]-1,2^a[j]-1)==2^a[j]-1)

                  DoorNumber=DoorNumber+1;
             else 
                  DoorNumber=DoorNumber-GCD(2^a[i]-1,2^a[j]-1);

print DoorNumber

NOTE:Here "^" is not xor operator , it is meant for power here.

Input:
First line contains a integer "T" ,number of test cases .Each test case contain two lines , first line contains value of ArraySize (size of array) and second line contain values of array elements
.

Output:
For each test case print the value of DoorNumber.

Constraints:
1<=T<=20
1<=ArraySize<=10^5
1<=a[i]<=100

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
Basic ProgrammingNumber theory
Points:30
4 votes
Tags:
Basic ProgrammingGCDMathNumber Theory
Points:30
Tags:
MathematicsMediumOpenApprovedNumber Theory