51nod1239 欧拉函数之和
跟1244差不多。
//由于(x+1)没有先mod一下一直WA三个点我。。。
//由于(x+1)没有先mod一下一直WA三个点我。。。
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(ll i=s;i<=t;i++)
#define dwn(i,s,t) for(ll i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define qwq(x) for(edge *o=head[x];o;o=o->next)
#define ll long long
const ll md=1e6+7;
const ll mod=1e9+7;
const int nmax=6e6+5;
struct edge{
ll to,dis;edge *next;
};
edge es[md<<1],*pt=es,*head[md];
ll pi[nmax+1];int pe[nmax+1];bool vis[nmax+1];
void add(ll u,ll v,ll d){
pt->to=v;pt->dis=d;pt->next=head[u];head[u]=pt++;
}
const ll zs=500000004;
ll get(ll x){
if(x<=nmax) return pi[x];
ll tp=x%md;qwq(tp) if(o->to==x) return o->dis;
ll ans=0,last;
for(ll i=2;i<=x;i=last+1){
last=x/(x/i);
ans=(ans+(last-i+1)%mod*get(x/i)%mod)%mod;
}
ll orz=(x%mod*((x+1)%mod)%mod*zs%mod-ans+mod)%mod;
add(tp,x,orz);
return orz;
}
int main(){
pi[1]=1;int cnt=0,tp;
rep(i,2,nmax){
if(!vis[i]) pe[++cnt]=i,pi[i]=i-1;
rep(j,1,cnt){
tp=pe[j];if(i*tp>nmax) break;vis[i*tp]=1;
if(i%tp==0){
pi[i*tp]=pi[i]*tp;break;
} pi[i*tp]=pi[i]*pi[tp];
}
}
rep(i,2,nmax) pi[i]=(pi[i]+pi[i-1])%mod;
ll n;scanf("%lld",&n);
printf("%lld\n",get(n));
return 0;
}
输入一个数N。(2 <= N <= 10^10)
输出S(n) Mod 1000000007的结果。
5
10
51nod1239 欧拉函数之和的更多相关文章
- [51nod1239欧拉函数之和]
来自FallDream的博客,未经允许,请勿转载,谢谢 --------------------------------------------- 给定n,求$S(n)=\sum_{i=1}^{n}\ ...
- 杜教筛--51nod1239 欧拉函数之和
求$\sum_{i=1}^{n}\varphi (i)$,$n\leqslant 1e10$. 这里先把杜教筛的一般套路贴一下: 要求$S(n)=\sum_{i=1}^{n}f(i)$,而现在有一数论 ...
- [51nod1239] 欧拉函数之和(杜教筛)
题面 传送门 题解 话说--就一个杜教筛--刚才那道拿过来改几行就行了-- //minamoto #include<bits/stdc++.h> #define R register #d ...
- 51 NOD 1239 欧拉函数之和(杜教筛)
1239 欧拉函数之和 基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 收藏 关注 对正整数n,欧拉函数是小于或等于n的数中与n互质的数的数目.此函数以其首名研究 ...
- [51Nod 1244] - 莫比乌斯函数之和 & [51Nod 1239] - 欧拉函数之和 (杜教筛板题)
[51Nod 1244] - 莫比乌斯函数之和 求∑i=1Nμ(i)\sum_{i=1}^Nμ(i)∑i=1Nμ(i) 开推 ∑d∣nμ(d)=[n==1]\sum_{d|n}\mu(d)=[n== ...
- 【51nod-1239&1244】欧拉函数之和&莫比乌斯函数之和 杜教筛
题目链接: 1239:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 1244:http://www.51nod. ...
- 51nod 1239 欧拉函数之和(杜教筛)
[题目链接] https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 [题目大意] 计算欧拉函数的前缀和 [题解] 我们 ...
- 欧拉函数之和(51nod 1239)
对正整数n,欧拉函数是小于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商数等.例如:φ(8) = 4(Phi( ...
- 【51Nod 1239】欧拉函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 还是模板题. 杜教筛:\[S(n)=\frac{n(n+1)}{2 ...
随机推荐
- LCIS(m*n) 最长公共上升子序列
详见:http://wenku.baidu.com/view/3e78f223aaea998fcc220ea0n3的: for(int i=1;i<=n;i++) for ...
- Sqli-labs less 56
Less-56 与less54.55形式是一致的,我们关注sql语句, $sql="SELECT * FROM security.users WHERE id=('$id') LIMIT 0 ...
- (转)排列算法 Permutation Generation
转自:http://www.cnblogs.com/dragonpig/archive/2010/01/21/1653680.html http://www.notesandreviews.com/p ...
- Wamp Mysql错误消息 语言设置
Wamp Mysql错误消息 语言设置 http://my.oschina.net/wandershi/blog/264347 打开my.ini 找到 [wampmysqld] port = 33 ...
- iOS后台运行
http://www.cocoachina.com/bbs/read.php?tid=149564 文一 我从苹果文档中得知,一般的应用在进入后台的时候可以获取一定时间来运行相关任务,也就是说可以在后 ...
- ios下划线变量:为什么变量前要加下划线才有用?
先看一段代码. 复制代码 appdelegate.h @property (weak) IBOutlet NSMatrix *StockType; @property (weak) IBOutle ...
- poj 1724(有限制的最短路)
题目链接:http://poj.org/problem?id=1724 思路: 有限制的最短路,或者说是二维状态吧,在求最短路的时候记录一下花费即可.一开始用SPFA写的,900MS险过啊,然后改成D ...
- tvm install
一.系统需求:1.可以访问互联网2.关闭防火墙和selinux 二.安装步骤(进入软件包所在目录):1.rpm -ivh daemontools-0.76-1.el6.x86_64.rpm2.yum ...
- 【PSR规范专题(2)】PSR-1 基本代码规范
转载自: https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-1-basic-coding-standard-cn.md 基本代码规范 本篇规范制定 ...
- java中静态代理跟动态代理之间的区别
文章转载于:http://www.cnblogs.com/xiaoluo501395377/p/3383130.html 在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另 ...