题意:

已知\(f(n,a,b)=\sum_{i=1}^n\sum_{j=1}^igcd(i^a-j^a,i^b-j^b)[gcd(i,j)=1]\mod 1e9+7\),\(n\leq1e9\),且保证\(ab\)互质,求\(f(n,a,b)\)

思路:

由不知道什么得:当\(ab\)互质,则\(gcd(i^a-j^a,i^b-j^b)=i-j\)。

那么可转化为:

\[\begin{aligned}
&\sum_{i=1}^n\sum_{j=1}^ii-j[gcd(i,j)=1]\mod 1e9+7\\
=&\sum_{i=1}^ni\varphi(i)-\frac{i*\varphi(i)}{2}\\
=&\frac{1}{2}(\sum_{i=1}^ni\varphi(i) \ \ \ - 1)
\end{aligned}
\]

那么问题转化为求:\(\sum_{i=1}^ni\varphi(i)\),因为前缀和有点大,所以估计要用到杜教筛,所以先卷积一下:

\[\begin{aligned}
(f*g)(n)=&\sum_{d|n}f(d)g(\frac{n}{d})\\
=&\sum_{d|n}i\varphi(i)g(\frac{n}{d})
\end{aligned}
\]

为了让卷积完的\(h\)和\(g\)前缀更好求,那么这里不如令\(g=id\),那么\((f*g)(n)=n*\sum_{d|n}\varphi(d)\),又因为\(\varphi*I=id\),故\((f*g)(n)=n^2\)。

所以可得终式:

\[S(n)=\sum_{i=1}^ni^2-\sum_{i=2}iS(\lfloor\frac{n}{i}\rfloor)
\]

因为超过\(1e6\)只有\(10\)组,所以我这里直接手动哈希比\(map\)快一点。

代码:

#include<map>
#include<set>
#include<cmath>
#include<cstdio>
#include<stack>
#include<ctime>
#include<vector>
#include<queue>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 4e6 + 5;
const ll MOD = 1e9 + 7;
const ull seed = 131;
const int INF = 0x3f3f3f3f; int mark[maxn], prime[maxn], tot;
ll phi[maxn];
void init(int n){
tot = 0;
int i, j;
phi[1] = 1;
for(i = 2; i <= n; i++){
if(!mark[i]){
prime[++tot] = i;
phi[i] = i - 1;
}
for(j = 1; j <= tot; j++){
if(i * prime[j] > n) break;
mark[i * prime[j]] = 1;
if(i % prime[j] == 0){
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else phi[i * prime[j]] = phi[i] * (prime[j] - 1);
}
} phi[0] = 0;
for(int i = 1; i <= n; i++){
phi[i] = (1LL * phi[i] * i + phi[i - 1]) % MOD;
}
} ll inv6 = 166666668, inv2 = 500000004;
ll mphi[100000], UP;
int vis[100000];
int N = 4e6;
ll getans(int x){
return x <= N? phi[x] : mphi[UP / x];
}
ll ksc(ll a, ll b, ll p){
ll t = a * b - (ll)((long double)a * b / p + 0.5) * p;
return (t < 0)? t + p : t;
}
void solve(int n){
int t = UP / n;
if(n <= N) return;
if(vis[t]) return;
vis[t] = 1;
mphi[t] = ksc(ksc(n, n + 1, MOD), 2 * n + 1, MOD) * inv6 % MOD;
for(int l = 2, r; l <= n; l = r + 1){
r = n / (n / l);
solve(n / l);
mphi[t] -= 1LL * (l + r) * (r - l + 1) % MOD * inv2 % MOD * getans(n / l) % MOD;
mphi[t] %= MOD;
}
}
int main(){
int T;
init(N);
// init(N + 1);
// printf("%lld\n", (phi[N + 1] - 1) * inv2 % MOD);
scanf("%d", &T);
while(T--){
ll ans;
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
if(n <= N) ans = phi[n];
else{
UP = n;
memset(vis, 0, sizeof(vis));
solve(n), ans = mphi[1];
}
ans = (ans - 1) * inv2;
ans = (ans % MOD + MOD) % MOD;
printf("%lld\n", ans);
}
return 0;
}

HDU 6706 huntian oy(杜教筛 + 一些定理)题解的更多相关文章

  1. CCPC 2019 网络赛 HDU huntian oy (杜教筛)

    1005 huntian oy (HDU 6706) 题意: 令,有T次询问,求 f(n, a, b). 其中 T = 10^4,1 <= n,a,b <= 1e9,保证每次 a,b互质. ...

  2. HDU6706 huntian oy(2019年CCPC网络赛+杜教筛)

    目录 题目链接 思路 代码 题目链接 传送门 思路 看到这题还比较懵逼,然后机房大佬板子里面刚好有这个公式\(gcd(a^n-b^n,a^m-b^m)=a^{gcd(n,m)}-b^{gcd(n,m) ...

  3. [HDU 5608]Function(莫比乌斯反演 + 杜教筛)

    题目描述 有N2−3N+2=∑d∣Nf(d)N^2-3N+2=\sum_{d|N} f(d)N2−3N+2=∑d∣N​f(d) 求∑i=1Nf(i)\sum_{i=1}^{N} f(i)∑i=1N​f ...

  4. HDU 5608 function(莫比乌斯反演 + 杜教筛)题解

    题意: 已知\(N^2-3N+2=\sum_{d|N}f(d)\),求\(\sum_{i=1}^nf(i) \mod 1e9+7\),\(n\leq1e9\) 思路: 杜教筛基础题? 很显然这里已经设 ...

  5. HDU 6987 - Cycle Binary(找性质+杜教筛)

    题面传送门 首先 mol 一发现场 AC 的 csy 神仙 为什么这题现场这么多人过啊啊啊啊啊啊 继续搬运官方题解( 首先对于题目中的 \(k,P\)​,我们有若存在字符串 \(k,P,P'\)​ 满 ...

  6. luoguP4213 【模板】杜教筛(Sum)杜教筛

    链接 luogu 思路 为了做hdu来学杜教筛. 杜教筛模板题. 卡常数,我加了register居然跑到不到800ms. 太深了. 代码 // luogu-judger-enable-o2 #incl ...

  7. 51nod 1244 莫比乌斯函数之和(杜教筛)

    [题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...

  8. 51nod 1237 最大公约数之和 V3(杜教筛)

    [题目链接] https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1237 [题目大意] 求[1,n][1,n]最大公约数之和 ...

  9. 杜教筛 && bzoj3944 Sum

    Description Input 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 Output 一共T行,每行两个用空格分隔的数ans1,ans ...

随机推荐

  1. PAT练习num2-挖掘机技术哪家强

    为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第 1 行给出不超过 1 的正整数 N,即参赛人数.随后 N 行, ...

  2. LocalDateTime、OffsetDateTime、ZonedDateTime互转,这一篇绝对喂饱你

    前言 你好,我是A哥(YourBatman). 在JSR 310日期时间体系了,一共有三个API可用于表示日期时间: LocalDateTime:本地日期时间 OffsetDateTime:带偏移量的 ...

  3. 翻译 - ASP.NET Core 基本知识 - Web 主机 (Web Host)

    翻译自 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-5.0 ASP. ...

  4. ETCD数据迁移

    ETCD数据迁移 本文阅读对象为想要将Rainbond平台rbd-etcd切换至外部etcd的相关人员. 在k8s master节点创建secret 本文中将要切换的ETCD为根据Rainbond官方 ...

  5. ctfshow_djb杯

    桐桑又开始摸鱼了 ctfshow的比赛整的一手好活.djb杯. web1_veryphp 打开就是源码: 1 <?php 2 error_reporting(0); 3 highlight_fi ...

  6. 🙈 如何隐藏你的热更新 bundle 文件?

    如果你喜欢我写的文章,可以把我的公众号设为星标 ,这样每次有更新就可以及时推送给你啦. 前段时间我们公司的一个大佬从一些渠道得知了一些小道消息,某国民级 APP 因为 Apple App Store ...

  7. (转载)微软数据挖掘算法:Microsoft 聚类分析算法(2)

    介绍: Microsoft 聚类分析算法是一种"分段"或"聚类分析"算法,它遍历数据集中的事例,以将它们分组到包含相似特征的分类中. 在浏览数据.标识数据中的异 ...

  8. Python基础(if语句、运算符)

    if语句的简单用法 每条if 语句的核心都是一个值为True 或False 的表达式 (简称条件测试),python根据条件测试的值来判断是否执行if语句后面的代码块,如果为true,执行:为fals ...

  9. 2021最新 Spring面试题精选(附刷题小程序)

    推荐使用小程序阅读 为了能让您更加方便的阅读 本文所有的面试题目均已整理至小程序<面试手册> 可以通过微信扫描(或长按)下图的二维码享受更好的阅读体验! 目录 推荐使用小程序阅读 1. S ...

  10. java小技巧

    String 转 Date String classCode = RequestHandler.getString(request, "classCode"); SimpleDat ...