poj 2480 Longge's problem 积性函数
思路:首先给出几个结论:
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 积性函数的更多相关文章
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- 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 ...
- POJ 2480 Longge's problem 积性函数
题目来源:id=2480" style="color:rgb(106,57,6); text-decoration:none">POJ 2480 Longge's ...
- poj 2480 Longge's problem 积性函数性质+欧拉函数
题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...
- 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的因子.为什么呢?原因 ...
- 题解报告:poj 2480 Longge's problem(欧拉函数)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
- poj 2480 Longge's problem
/** 大意: 计算f(n) = ∑ gcd(i, N) 1<=i <=N. 思路: gcd(i,x*y) = gcd(i,x) * gcd(i, y ) 所以gcd 为积性函数 又因为积 ...
- [poj 2480] Longge's problem 解题报告 (欧拉函数)
题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<al ...
随机推荐
- qu
离骚 (3481人评分) 8.5 朝代:先秦 作者:屈原 原文: 帝高阳之苗裔兮,朕皇考曰伯庸.摄提贞于孟陬兮,惟庚寅吾以降.皇览揆余初度兮,肇锡余以嘉名:名余曰正则兮,字余曰灵均.纷吾既有此内美 ...
- 如何用nodejs写入mysql 的blob格式的数据
So, if the array length equals 4, then the size of blob data in mysql DB must be 4 bytes. And it wor ...
- php中$this、static、final、const、self 等几个关键字的用法
<?phpclass A { public static function get_self(){ return new self(); } public static function get ...
- 硬件描述语言Verilog设计经验总结
一.硬件描述语言Verilog 粗略地看Verilog与C语言有许多相似之处.分号用于结束每个语句,注释符也是相同的(/* ... */和// 都是熟悉的),运算符"=="也用来测 ...
- P1572: [Usaco2009 Open]工作安排Job
做这道题走了不少弯路,其实本身也是很简单的,类似单调队列的东西.刚开始以为双关键字排序就行了,结果连WA两遍,忽然意识到可以在截止之前做这件事!!于是就规规矩矩的打队列,然而忘记找队列里的最小P做,当 ...
- Java存储密码用字符数组
字符数组和字符串都可以用于存储文本数据,但是在选择具体哪一种时,如果你没有针对具体的情况是很难回答这个问题的.但是任何与字符串相关的问题一定有线索可以在字符串的属性里面找到,比如不可变性.他就用这种方 ...
- xml基础学习笔记01
注意:刚刚看了网上对于XML中的标签,节点和元素?到底应该怎么表述?起初我也有这个疑惑,现在我的想法是:下面出现node的应称作节点,节点对象.element应称作元素,毕竟这更符合英文的本意.至于标 ...
- Kibana4学习<一>
Kibana4 安装方式依然简单,你可以在几分钟内安装好 Kibana 然后开始探索你的 Elasticsearch 索引.只需要预备: Elasticsearch 1.4.4 或者更新的版本 一个现 ...
- JavaScript 函数调用
JavaScript 函数有 4 种调用方式. 每种方式的不同方式在于 this 的初始化. this 关键字 一般而言,在Javascript中,this指向函数执行时的当前对象. 注意 this ...
- HDU 3555 Bomb 数位dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...