BZOJ 4916 神犇和蒟蒻(杜教筛)
来源:互联网 发布:淘宝助理导出数据包 编辑:程序博客网 时间:2024/06/05 07:51
Description
很久很久以前,有一只神犇叫yzy;
很久很久之后,有一只蒟蒻叫lty;
Input
请你读入一个整数N;1<=N<=1E9,A、B模1E9+7;
Output
请你输出一个整数
请你输出一个整数
Sample Input
1
Sample Output
1
1
Solution
因为
其中
所以
题目就是求
这个利用狄利克雷卷积知识就可以知道,
即
我们设
因此
Code
#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <cmath>#include <algorithm>#define N 1000010#define M 2333333#define Mod 1000000007using namespace std;typedef long long LL;int n, cnt;bool vis[N];int prime[N];LL phi[N], hash_v[M], hash_n[M];void Da(){ vis[1] = true; phi[1] = 1ll; for(int i = 2; i < N; i++){ if(!vis[i]){ prime[++cnt] = i; phi[i] = (LL)(i-1); } for(int j = 1; j <= cnt && i * prime[j] < N; j++){ vis[i * prime[j]] = true; if(i % prime[j] == 0){ phi[i * prime[j]] = phi[i] * (LL)prime[j]; break; } else phi[i * prime[j]] = phi[i] * (LL)(prime[j]-1); } } for(int i = 1; i < N; i++){ phi[i] = phi[i] % Mod * i % Mod; phi[i] = (phi[i] + phi[i-1]) % Mod; }}LL Find(LL x){ int p = x % M; while(hash_n[p] && hash_n[p] != x) p = (p+1) % M; if(!hash_n[p]) return -1; return hash_v[p];}void Push(LL v, LL x){ int p = x % M; while(hash_n[p]) p = (p+1) % M; hash_v[p] = v; hash_n[p] = x;}LL Sum(LL x){ if(x < N) return phi[x]; LL res = Find(x); if(~ res) return res; else{ LL temp1 = x * (x + 1), temp2 = 2 * x + 1; if(!(temp1 % 6)) temp1 /= 6; else if(!(temp2 % 6)) temp2 /= 6; else if(!(temp1 % 2) && !(temp2 % 3)) temp1 /= 2, temp2 /= 3; else if(!(temp2 % 2) && !(temp1 % 3)) temp1 /= 3, temp2 /= 2; res = ((temp1 % Mod) * (temp2 % Mod)) % Mod; } LL last; for(LL i = 2; i <= x; i = last+1){ last = x/(x/i); res = (res - (((last+i) * (last-i+1) / 2) % Mod * Sum(x/i)) % Mod + Mod) % Mod; } Push(res, x); return res;}int main(){ freopen("bzoj4916.in", "r", stdin); freopen("bzoj4916.out", "w", stdout); Da(); scanf("%lld", &n); printf("1\n%lld\n", Sum(n)); return 0;}
阅读全文
1 0
- bzoj 4916 神犇和蒟蒻
- BZOJ 4916 神犇和蒟蒻
- bzoj 4916: 神犇和蒟蒻
- BZOJ 4916: 神犇和蒟蒻 杜教筛 数学
- [杜教筛] BZOJ 4916 神犇和蒟蒻
- bzoj 4916: 神犇和蒟蒻 杜教筛
- BZOJ 4916 神犇和蒟蒻(杜教筛)
- bzoj 1303 |前缀和
- [杜教筛 约数个数前缀和] BZOJ 4176 Lucas的数论
- BZOJ 4636: 蒟蒻的数列
- BZOJ 4636 蒟蒻的数列
- BZOJ蒟蒻百年挖坑计划
- BZOJ-2337-XOR和路径
- bzoj 3398 牡牛和牝牛
- bzoj 2257 瓶子和燃料
- BZOJ 1218 二维前缀和
- bzoj 2956: 模积和
- [BZOJ]1056 和 1862 splay
- codevs1074 洛谷2024 带权并查集
- MapReduce对输入多文件的处理
- 【NYOJ
- 第四章 Thread Executors(Executors多线程架构)【上】
- qduoj codeforces 山东省第八届acm省赛K题 CF (排序+01背包)
- BZOJ 4916 神犇和蒟蒻(杜教筛)
- 可以直接在QQ上直接提取图片的文字啦
- 最大公约数(最小公倍数)
- iOS之NSAttributedString属性值
- HDU 6127 Hard challenge (极角排序+二分, 2017 Multi-Univ Training Contest 7)
- HDU 2222:Keywords Search(AC自动机入门题)
- 安装loadrunner11的时候提示'命令行选项语法错误。键入命令 / ?’ 怎么办
- Android 与 设计模式(2)——工厂模式
- JZOJ1263. 巴比伦 (2017.8B组)