思路:首先给出几个结论:

1.gcd(a,b)是积性函数;

2.积性函数的和仍然是积性函数;

3.phi(a^b)=a^b-a^(b-1);

记 f(n)=∑gcd(i,n),n=p1^e1*p2^e2……;

则 f(n)=∑d*phi(n/d) (d是n的约数)

          =∑(pi*ei+pi-ei)*pi^(ei-1).

代码如下:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#define ll __int64
#define M 50005
#define inf 1e10
#define mod 1000000007
using namespace std;
int prime[M],cnt;
bool f[M];
void init()
{
cnt=;
memset(f,,sizeof(f));
for(int i=;i<M;i++){
if(!f[i]) prime[cnt++]=i;
for(int j=;j<cnt&&i*prime[j]<M;j++){
f[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
}
ll pows(ll a,ll b)
{
ll ans=;
while(b){
if(b&) ans*=a;
b>>=;
a*=a;
}
return ans;
}
ll dfs(ll n)
{
ll ans=,j;
for(int i=;i<cnt&&prime[i]*prime[i]<=n;i++){
if(n%prime[i]==){
j=;
n/=prime[i];
while(n%prime[i]==){
j++;
n/=prime[i];
}
ans*=(ll)(prime[i]*j-j+prime[i])*pows(prime[i],j-);
}
}
if(n>) ans*=(ll)(*n-);
return ans;
}
int main()
{
ll n;
init();
while(scanf("%I64d",&n)!=EOF){
printf("%I64d\n",dfs(n));
}
return ;
}

poj 2480 Longge's problem 积性函数的更多相关文章

  1. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  2. poj 2480 Longge's problem 欧拉函数+素数打表

    Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathem ...

  3. POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 ...

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

    题目来源:id=2480" style="color:rgb(106,57,6); text-decoration:none">POJ 2480 Longge's ...

  5. 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 ...

  6. POJ 2480 Longge's problem (积性函数,欧拉函数)

    题意:求∑gcd(i,n),1<=i<=n思路:f(n)=∑gcd(i,n),1<=i<=n可以知道,其实f(n)=sum(p*φ(n/p)),其中p是n的因子.为什么呢?原因 ...

  7. 题解报告:poj 2480 Longge's problem(欧拉函数)

    Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...

  8. poj 2480 Longge's problem

    /** 大意: 计算f(n) = ∑ gcd(i, N) 1<=i <=N. 思路: gcd(i,x*y) = gcd(i,x) * gcd(i, y ) 所以gcd 为积性函数 又因为积 ...

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

    题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<al ...

随机推荐

  1. net-snmp的安装

    安装环境是ubuntu 14. 方法1:apt-get install  net-snmp (非root用户需要sudo 提升权限) 方法2:自定义安装选择不同的版本去编译. 1:先去下载所需要的ta ...

  2. UserDefault 用户首选项读写 swift

    // // ViewController.swift // 首选项数据读写 // // Created by mac on 15/7/12. // Copyright (c) 2015年 fangyu ...

  3. tcp传输黏包

    tcp传输黏包 tcpip协议使用"流式"(套接字)进行数据的传输,就是说它保证数据的可达以及数据抵达的顺序,但并不保证数据是否在你接收的时候就到达,特别是为了提高效率,充分利用带 ...

  4. css3 forwards、backwards、both

    animation-fill-mode 属性规定动画在播放之前或之后,其动画效果是否可见. none 不改变默认行为. forwards 当动画完成后,保持最后一个属性值(在最后一个关键帧中定义). ...

  5. Node.js 学习(一) 安装配置

    Windowv 上安装Node.js Windows 安装包(.msi) : 32 位安装包下载地址 : http://nodejs.org/dist/v0.10.26/node-v0.10.26-x ...

  6. android手机配置hosts文件

    Android设备测试服务器时,可能需要修改 hosts 文件指定域名到对应的 IP 地址.Android 是基于 Linux 的系统,与 Linux 类似,通过 hosts 文件来设置. 在 And ...

  7. 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉

    DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $  当然这里的$i$和$k$都是偶数啦~ ...

  8. Windows+Apache+MySQL+PHP(WAMP)环境搭建

    运行操作系统:Windows Server 2008 R2 Apache版本:Apache 2.2 MySQL版本:MySQL 5.5 PHP版本:PHP 5.6.14(当前最新版) 更新日期:201 ...

  9. 使用JFinal-weixin配置微信开发

    先扯点闲话,申请好公众号后,一直因为没有域名.没有外网IP而没有尝试过开发微信服务.后来发现nat123可以从内网直接映射到外网,但是nat123需要钱或者T币大于0,于是为了赚一个T币,签到灌水了一 ...

  10. 系统使用 aspose.cell , 使得ashx第一次访问会变很慢

      网站放在IIS后, 在网站第一次访问后.  回收应用程序池 第一次访问aspx页面还是比较快.   但第一次访问ashx会很慢.   后发现原因: aspose.cell的5.3...版本. 的原 ...