POJ 2480 Longge's problem

gcd(i,n)=p
gcd(i/p,n/p)=p
若p是n的约数,那么gcd(i,n)==p的有φ(n/p)
∑ i*euler(n/i)+(n/i)*euler(i)   (n%i==0)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
inline void read(long long &a)
{
    long long k=1; a=0; char c=getchar();
    while(c<‘0‘||‘9‘<c){if(c==‘-‘)k=-1; c=getchar();}
    while(‘0‘<=c&&c<=‘9‘){a=a*10+c-‘0‘; c=getchar();}
    a*=k;
}
inline void write(long long a)
{
    if (a<0){putchar(‘-‘);a=-a;}
    if (a>9)write(a/10);
    putchar(a%10+‘0‘);
    return ;
}
long long euler(long long x)
{
    long long now=x,i;
    for(i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        {
            now=now/i*(i-1);
            while(x%i==0)
            x/=i;
        }
    }
    if(x>1)
    now=now/x*(x-1);
    return now;
}
int main()
{
    long long n,i;
    while (~scanf("%lld",&n))
    {
        long long ans=0;
        for (i=1;i<sqrt(n);i++)
        {
            if (n%i==0)
            ans+=i*euler(n/i)+(n/i)*euler(i);
        }
        if (i*i==n)
        ans+=i*euler(i);
        cout<<ans<<endl;
    }
    return 0;
}

POJ 2480 Longge's problem

原文地址:https://www.cnblogs.com/applechina/p/10556174.html

时间: 2024-10-12 12:24:38

POJ 2480 Longge's problem的相关文章

POJ 2480 Longge&#39;s problem 积性函数

题目来源:POJ 2480 Longge's problem 题意:求i从1到n的gcd(n, i)的和 思路:首先如果m, n 互质 gcd(i, n*m) = gcd(i, n)*gcd(i, m) 这是一个积性函数积性函数的和还是积性函数 由欧拉函数知识得 phi(p^a) = p^a - p^(a-1) p是素数 a是正整数 得到最终答案f(n) = f(p1^a1)*f(p2^a2)*...*f(pn^an) 其中f(p^a) = a*(p^a-p^(a-1))+p^a #includ

poj 2480 Longge&#39;s problem 积性函数性质+欧拉函数

题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d | n}phi(n / d) * d ,后者是积性函数),可以这么解释:当d是n的因子时,设1至n内有a1,a2,..ak满足gcd(n,ai)==d,那么d这个因子贡献是d*k,接下来证明k=phi(n/d):设gcd(x,n)==d,那么gcd(x/d,n/d)==1,所以满足条件的x/d数目为phi(

poj 2480 Longge&#39;s problem [ 欧拉函数 ]

传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2416 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms.

POJ 2480 Longge&#39;s problem (欧拉函数+乘性函数)

Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7343   Accepted: 2422 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now

[poj 2480] Longge&#39;s problem 解题报告 (欧拉函数)

题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<algorithm> #include<cstdio> #include<iostream> #include<cmath> using namespace std; typedef long long ll; const int N=(1<<31)+15;

题解报告:poj 2480 Longge&#39;s problem(欧拉函数)

Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. 

poj 2480 Longge&amp;#39;s problem 积性函数性质+欧拉函数

题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d | n}phi(n / d) * d ,后者是积性函数),能够这么解释:当d是n的因子时,设1至n内有a1,a2,..ak满足gcd(n,ai)==d,那么d这个因子贡献是d*k,接下来证明k=phi(n/d):设gcd(x,n)==d,那么gcd(x/d,n/d)==1,所以满足条件的x/d数目为phi(

POJ 2480 Longge&amp;#39;s problem 积性函数

题目来源:POJ 2480 Longge's problem 题意:求i从1到n的gcd(n, i)的和 思路:首先假设m, n 互质 gcd(i, n*m) = gcd(i, n)*gcd(i, m) 这是一个积性函数积性函数的和还是积性函数 由欧拉函数知识得 phi(p^a) = p^a - p^(a-1) p是素数 a是正整数 得到终于答案f(n) = f(p1^a1)*f(p2^a2)*...*f(pn^an) 当中f(p^a) = a*(p^a-p^(a-1))+p^a #includ

【POJ】2480 Longge&#39;s problem(欧拉函数)

题目 传送门:QWQ 分析 题意就是求∑gcd(i, N) 1<=i <=N.. 显然$ gcd(i,n) = x $时,必然$x|n$. 所以我们枚举一下n的约数,对于每个约数x,显然$ gcd(i/x,n/x)=1$ 所以我们计算一下n/x的欧拉函数就ok了. 联赛前刷水题qwq 代码 // #include <bits/stdc++.h> #include <cstdio> #include <cmath> #include <algorithm