Goffi and GCD (Euler function and its properties)

Goffi and GCD

Title:

Insert picture description here

因为 g c d ( n − i , n ) , g c d ( n − j , n ) gcd(n-i,n),gcd(n-j,n) gcd(ni,n ) g c d ( nj,n ) are all factors of n (and not n), so the multiplication will not exceedn 2 n^2n2 So it is equivalent to seeking
Insert picture description here

Pusher

= I = 1 n ∑ j = 1 n [gcd (n - i, n) gcd (n - j, n) = n] = i = 1 n ∑ j = 1 n ∑ x ∣ n ∑ y ∣ n [xy = n] [gcd (n - i, n) = x] [gcd (n - j, n) = y] ∑ x ∣ n ∑ y ∣ n [xy = n] = i = 1 n [gcd (i, n) = x] ∑ j = 1 n [gcd (j, n) = x] ∑ x ∣ n ∑ y ∣ n [xy = n] ϕ (nx) ϕ (ny) ∑ x ∣ n ϕ (nx) ϕ (x) \ sum_ = i = 1} ^ n \ sum_ {j = 1} ^ {n} [gcd (ni, n) gcd (nj, n) = n] \\ \ sum_ {i = 1} ^ n \ sum_ {j = 1} ^ n \ sum_ {x | n} \ sum_ {y | n} [xy = n] [gcd (ni, n) = x] [gcd (nj, n) = y] \\ \ sum_ {x | n} \ sum_ {y | n} [xy = n] \ sum_ {i = 1} ^ n [gcd (i, n) = x] \ sum_ {j = 1} ^ n [gcd ( j, n) = x] \\ \ sum_ {x | n} \ sum_ {y | n} [xy = n] \ phi (\ frac nx) \ phi (\ frac ny) \\ \ sum_ {x | n ph \ phi (\ frac nx) \ phi (x) \\ i=1nj=1n[gcd(ni,n ) g c d ( nj,n)=n]i=1nj=1nxnyn[xy=n ] [ g c d ( ni,n)=x][gcd(nj,n)=and ]xnyn[xy=n]i=1n[gcd(i,n)=x]j=1n[gcd(j,n)=x]xnyn[xy=n ] ϕ (xn) ϕ (andn)xnϕ (xn) ϕ ( x )

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll eular(ll x) {
    
    //利用欧拉函数的性质求phi(x)
    ll ans = x;
    for(ll i=2; i*i<=x; i++) {
    
    
        if(x % i == 0) {
    
    
            ans = ans/i*(i-1);
            while(x % i == 0) x /= i;
        }
    }
    if(x > 1) ans = ans/x*(x-1);
    return ans; 
}
int main() {
    
    
    ll n, m;
    while(scanf("%lld %lld", &n, &m) != EOF) {
    
    
        ll ans = 0;
        if(m == 2 || n == 1) ans = 1;
        else  if(m == 1){
    
    
            for(ll i=1; i*i<=n; i++) {
    
    
                if(n % i == 0) {
    
    
                    if(n/i != i) ans = (ans+eular(i)*eular(n/i)*2%mod)%mod;
                    else ans = (ans+eular(i)*eular(i)%mod)%mod;
                }
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

End

Guess you like

Origin blog.csdn.net/weixin_45363113/article/details/111658232