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 ...
随机推荐
- Sqli-labs less 27
Less-27 本关主要考察将union,select和26关过滤掉的字符.此处我们依旧和26关的方式是一样的,只需要将union和select改为大小写混合就可以突破. 示例:127.0.0.1/s ...
- BZOJ1083: [SCOI2005]繁忙的都市
水题之王SP…这题就裸的最小生成树 /************************************************************** Problem: 1083 User ...
- yum install 与 yum groupinstall 的区别
原文:http://blog.51yip.com/linux/1171.html yum 提供二种安装软件的方式 1,yum install 它安装单个软件,以及这个软件的依赖关系 2,yum gro ...
- 支持DISTINCT的通用分页存储过程(SQL2005)
/****** 对象: StoredProcedure [dbo].[P_CommonPagination] 脚本日期: 07/22/2009 10:22:01 ******/ SET ANSI_NU ...
- POJ 1986 Distance Queries (最近公共祖先,tarjan)
本题目输入格式同1984,这里的数据范围坑死我了!!!1984上的题目说边数m的范围40000,因为双向边,我开了80000+的大小,却RE.后来果断尝试下开了400000的大小,AC.题意:给出n个 ...
- php接收数据
http://lpladdyy.blog.163.com/blog/static/133999664201010264264585/ PHP默认只识别application/x-www.form-ur ...
- 【C语言】二维数组做形参
二维数组有两种形式: ①在栈上: int a[4][4] = {...}; ②在堆堆上: int ** a = new int *[4]; for ...
- 历代诗词咏宁夏注释2_----苍岩道人<登文昌阁>
登文昌阁[1] 苍岩道人 壮年碌碌走尘埃,此地清幽不肯来. 老去始惊春梦促,韶光易过槿花开.[2] 历朝兴废书千卷,万古忠奸土一堆.[3] 惟爱莎罗歌最好,闲时拍板满斟杯.[4] 注释 [说明]选自& ...
- 有用的一些web网站
1.http://www.aseoe.com/api-download/download.html 爱思资源网
- 初始JSON
SON是一种传输数据的格式(以对象为样板,本质上就是对象,但用途有区别,对象就是本地用的,json是用来传输的 JSON的两种静态方法: 1.JSON.parse(); string --> ...