Title Description
Description
Longge is very good at maths and he is very happy to challenge difficult math problems. Here's the problem:
To set an integer N, you need to ask for ΣGCD (i, N) (1<=i<=n).
Enter a description
Input Description
The first line contains an integer N, as shown in title
Output description
Output Description
The first line contains an integer that is the answer to the request.
Sample input
Sample Input
6
Sample output
Sample Output
15
Data range and Tips
Data Size & Hint
For 60% of data, 0<n<=2^16.
For 100% of data, 0<n<=2^32.
We set the number of GCD (i,n) =k I to A (K), so the answer is k1* (A (K1)) + K2 * (A (K2)) +...+ kp* (A (KP)), where K1 K2 ... KP is an approximate n of each. The number of 1-n that can be divisible by K is a total of n/k, and in this n/k number, some of the numbers gcd (i,n) =k, while some gcd (i,n) = CK (c>1,c∈r). Then we need to find out those numbers GCD (i,n) =k. First, the number K must meet GCD (k,n) =k, if you want k multiplied by a number can still satisfy the GCD (k,n) =k, then he multiply this number must be less than coprime and n/k, less than very good understanding. What I need to explain is why need coprime, take out a n/k factor (not including 1), get the number pk,n must divide the PK, so gcd (pk,n) is equal to k*p. We can use Euler functions to find the numbers less than and coprime. So, we just need to find out all the factors of N.
1#include <iostream>2#include <vector>3#include <cmath>4#include <cstring>5 using namespacestd;6 7vector<Long Long>Ys;8 9 Long LongN, ans;Ten One A Long LongPhiLong LongN) {//Euler functions - if(n = =1)return 1; - Long LongK =N; the for(inti =2; I*i <= N; i++) - if(n% i = =0) - { -K/=i; + while(n% i = =0) n/=i; -K *= I-1; + } A if(N >1) { atK/=N; -K *= (N-1); - } - returnK; - } - in intMain () { -CIN >>N; to intnn = floor (sqrt (n));//Upper Bounds + for(inti =1; I <= nn; i++)//find the Factor - if(n% i = =0) the if(I*i = =N) ys.push_back (i); * Else { $ Ys.push_back (i);Panax NotoginsengYs.push_back (n/i); - } the for(inti =0; I < ys.size (); i++) { +Ans + = ys[i] * PHI (N/ys[i]); A } thecout << ans <<"\ n"; + return 0; -}
The problem of SDOI2012 Longge