The GCD function
Practice
3.5 (52 votes)
Mathematics
Gcd
Math
Number theory
Problem
94% Success 9122 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an integer \(N\) and there is a function \(F(N)=\sum_{i=1}^{N} GCD(X,i)\). Here, GCD denotes the greatest common divisor. You are required to select an integer value \(X\) that is greater than or equal to 1.
Your task is to determine the following:
- The maximum possible value of \(F(N)\) that you can get
- The minimum \(X\) for which maximum value will be achieved
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- Next \(T\) lines contain a single integer \(N\).
Output format
Print \(T\) lines. For each test case:
- Print a single line containing two integers, the maximum value of \(F(N)\) and the minimum value of \(X\) for which \(F(N)\) is maximized.
Constraints
\(1 \leq T \leq 40\)
\(1 \leq N \leq 40\)
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
MathematicsOpenApprovedEasyGreatest common divisor
Points:20
2 votes
Tags:
MathematicsAlgorithmsNumber theory
Points:20
Tags:
ImplementationEasy
Editorial
Login to unlock the editorial