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

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. oracle 各种问题排查

    一.ORA-00257 ORA-00257归档日志写满,最简单方法.可以更改归档的大小. 二.job不自动运行解决方法 http://www.cnblogs.com/xbding/p/5861443. ...

  2. android开发图片分辨率问题解决方案

    dpi是什么呢? dpi是“dot per inch”的缩写,每英寸像素数. 四种密度分类: ldpi (low), mdpi (medium), hdpi (high), and xhdpi (ex ...

  3. ios9网络请求https适配

    发现问题:今天升级Xcode 7.0 bata发现网络访问失败.输出错误信息: The resource could not be loaded because the App Transport S ...

  4. 自学asp.net mvc(一)

    之前一直做asp.net的webform,现在想学习一下mvc,把自学中遇到的问题记录到博客. 一.codeplex上托管代码 1. 2. 3. 4. 5. 6. 7. 8. 9.

  5. C++ 类的前置声明

    http://www.2cto.com/kf/201311/260705.html    今天在研究C++”接口与实现分离“的时候遇到了一个问题,看似很小,然后背后的东西确值得让人深思!感觉在学习的过 ...

  6. jquery ajax 传递js对象到后台

    第一种:通过struts接收 (function ($) { $("#btnsave").click(function () { var params = {}; params[& ...

  7. (补)PSP三张表

    学生     司新红 日期  2014.3.14 教师  王建民 项目计划总结 编程 完善程序 测试程序 阅读书籍 日总计 周日 10:00-10:30 pm 0.5 周一 10:00-10:30 p ...

  8. 关于BaseAdapter的使用及优化心得(一)

    对于Android程序员来说,BaseAdapter肯定不会陌生,灵活而优雅是BaseAdapter最大的特点.开发者可以通过构造BaseAdapter并搭载到ListView或者GridView这类 ...

  9. 【Unique Binary Search Trees】cpp

    题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...

  10. JavaScript原型与原型链学习笔记

    一.什么是原型?原型是一个对象,其他对象可以通过它实现属性继承.简单的说就是任何一个对象都可以成为原型 prototype属性: 我们创建的每个函数都有一个prototype属性,这个属性是一个指针, ...