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 ...
随机推荐
- ipa上传到APP store
原地址:http://blog.csdn.net/akun1103/article/details/8632651 在itunes中创建程序 该部分内容继续以雪豹系统为例 打开https://itun ...
- 支持DISTINCT的通用分页存储过程(SQL2005)
/****** 对象: StoredProcedure [dbo].[P_CommonPagination] 脚本日期: 07/22/2009 10:22:01 ******/ SET ANSI_NU ...
- POJ 2000
#include<iostream> #include<cstdio> #define MAXN 10009 using namespace std; ]; int main( ...
- C# 设置程序开机自动运行(+注册表项)
有时候我们需要让软件安装好了,开机自动运行,这时我们需要把启动项加载到注册表中,需要注意的时现在很多杀毒软件在其他软件更改注册表的时候会有提示,可能会阻止.下面代码包含增加启动项到注册表和删除启动项. ...
- UVA 11481 - Arrange the Numbers 数学
Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You ca ...
- C之算法
1° 选择排序算法 核心思路如下图: 以字符串排序进行说明 #include <stdio.h> #include <string.h> #define SIZE ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- Tomcat中xml文件引入各种schma xsd问题原理
1.Tomcat下的xml引入各种xsd约束,其实是为了对应xml中用到的各个标签
- php 实现树形结构
<?phpclass Tree{ private $OriginalList; public $pk;//主键字段名 public $parentKey;//上级id字段名 public $ch ...
- 替换应用程序exe图标,主要使用BeginUpdateResource,UpdateResource API函数
替换应用程序exe图标,主要使用的API函数是BeginUpdateResource(),UpdateResource(),EndUpdateResource()来使用自定义的ico文件类替换exe程 ...