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 ...
随机推荐
- PHPStorm+PHP5.6+WIN7+IIS7
文件下载 以下为参考网址,如无法打开或变动,请自行搜索,获取最新版本文件请行搜索 PHP Manager:http://www.iis.net/downloads/community/2010/09/ ...
- 图解JavaScript执行环境结构
JavaScript引擎在开始编译代码的时候,会对JavaScript代码进行一次预编译,生成一个执行环境,比如如下代码: window.onload=function(){ function sub ...
- 历代诗词咏宁夏注释2_----苍岩道人<登文昌阁>
登文昌阁[1] 苍岩道人 壮年碌碌走尘埃,此地清幽不肯来. 老去始惊春梦促,韶光易过槿花开.[2] 历朝兴废书千卷,万古忠奸土一堆.[3] 惟爱莎罗歌最好,闲时拍板满斟杯.[4] 注释 [说明]选自& ...
- 2016PHP开发者大会
大会干货: Rasmus Lerdorf——<Speeding up the Web with PHP 7> PHP 7 is here. It brings drastic perfor ...
- 很不错的文章---【问底】徐汉彬:亿级Web系统搭建——单机到分布式集群
[导读]徐汉彬曾在阿里巴巴和腾讯从事4年多的技术研发工作,负责过日请求量过亿的Web系统升级与重构,目前在小满科技创业,从事SaaS服务技术建设. 大规模流量的网站架构,从来都是慢慢“成长”而来.而这 ...
- WCF分布式开发步步为赢(8):使用数据集(DataSet)、数据表(DataTable)、集合(Collection)传递数据
数据集(DataSet).数据表(DataTable).集合(Collection)概念是.NET FrameWork里提供数据类型,在应用程序编程过程中会经常使用其来作为数据的载体,属于ADO.NE ...
- hdu 1526(最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1526 思路:floyd求传递闭包,然后就是最大匹配了,不过一开始输入没看清,被坑了将近2个小时. #i ...
- 【HDU 5030】Rabbit's String (二分+后缀数组)
Rabbit's String Problem Description Long long ago, there lived a lot of rabbits in the forest. One d ...
- eclipse工程设置的问题
- 5分钟理解iaas paas saas三种云服务区别
随着云计算的大热,向我咨询云计算相关问题的童鞋也越来越多,其中最近问的比较多的一个问题便是云计算中的pass是什么意思?整好今天有空,统一给大家解释下pass是什么意思?和Iass.Sass之间有什么 ...