Xtreme gcd sum
Time limit4sMemory limit256 MB
Add the gcd of every tuple formed by picking one integer from each of the n given intervals and print the total modulo 1,000,000,007.
- Level
Hard8 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
You are given the integer constants . Run the code below to the end and find the value that is finally stored in sum.
sum = 0;
for (x1 = a1; x1 <= b1; x1++)
for (x2 = a2; x2 <= b2; x2++)
...
for (xn = an; xn <= bn; xn++)
sum = sum + gcd(x1, x2, ..., xn);
gcd returns the greatest common divisor of its arguments , and sum is a variable that holds an arbitrarily large integer.
Looks too easy? I think so too.
Input
The first line contains a natural number .
The -th of the next lines contains and , separated by a space.
and .
Output
C and C++ have no data type that holds an arbitrarily large integer, so print the value of sum modulo on one line.