[poj 2480] Longge'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;
ll n;
int main()
{
    //printf("%lld\n",phi(3));
    while (scanf("%lld",&n)!=EOF)
    {
        ll ans=n;
        for (ll i=2;i*i<=n;i++)
        {
            if (n%i) continue;
            //if (i==1) ans++;
            ll j=0;
            while (n%i==0) n/=i,j++;
            ans/=i;
            ans*=(i-1)*j+i;
        }
        if (n>1)
        {
            ans/=n;
            ans*=2*n-1;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

[poj 2480] Longge's problem 解题报告 (欧拉函数)

原文地址:https://www.cnblogs.com/xxzh/p/9646588.html

时间: 2024-08-04 00:58:16

[poj 2480] Longge's problem 解题报告 (欧拉函数)的相关文章

题解报告: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&#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 积性函数

题目来源: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

gcd(i,n)=pgcd(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> #i

[ACM] POJ 2154 Color (Polya计数优化,欧拉函数)

Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7630   Accepted: 2507 Description Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of th

POJ 2154 Color(组合数学-波利亚计数,数论-欧拉函数,数论-整数快速幂)

Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7693   Accepted: 2522 Description Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of th

POJ 2478 Farey Sequence 筛选法求欧拉函数

题目来源:POJ 2478 Farey Sequence 题意:输入n 求 phi(2)+phi(3)+phi(4)+...+phi(n) 思路:用类似筛法的方式计算phi(1), phi(2), ..., phi(n) 再求前缀和 #include <cstdio> #include <cstring> #include <cmath> //欧拉phi函数 const int maxn = 1000010; typedef long long LL; int eule