原题题面

Given you n,x,k , find the value of the following formula:
∑ a 1 = 1 n ∑ a 2 = 1 n . . . ∑ a x = 1 n ( ∏ j = 1 x a j k ) f ( g c d ( a 1 , a 2 , . . . a x ) ) ∗ g c d ( a 1 , a 2 , . . . a x ) \sum_{a_1=1}^{n}\sum_{a_2=1}^{n}...\sum_{a_x=1}^{n}(\prod_{j=1}^{x}a_{j}^{k})f(gcd(a_1,a_2,...a_x))*gcd(a_1,a_2,...a_x) ∑a1​=1n​∑a2​=1n​...∑ax​=1n​(∏j=1x​ajk​)f(gcd(a1​,a2​,...ax​))∗gcd(a1​,a2​,...ax​)
g c d ( a 1 , a 2 , … , a n ) gcd(a_1,a_2,…,a_n) gcd(a1​,a2​,…,an​) is the greatest common divisor of a 1 , a 2 , . . . , a − n a_1,a_2,...,a-n a1​,a2​,...,a−n.
The function f ( x ) f(x) f(x) is defined as follows:
If there exists an ingeter k k k ( k > 1 ) (k>1) (k>1) , and k 2 k^2 k2 is a divisor of x x x,
then f ( x ) = 0 f(x)=0 f(x)=0, else f ( x ) = 1 f(x)=1 f(x)=1.

输入格式

The first line contains three integers t , k , x ( 1 ≤ t ≤ 1 0 4 , 1 ≤ k ≤ 1 0 9 , 1 ≤ x ≤ 1 0 9 ) t,k,x (1≤t≤10^4,1≤k≤10^9,1≤x≤10^9) t,k,x(1≤t≤104,1≤k≤109,1≤x≤109)
Then t t t test cases follow. Each test case contains an integer n n n ( 1 ≤ n ≤ 2 × 1 0 5 ) (1≤n≤2×10^5) (1≤n≤2×105)

输出格式

For each test case, print one integer — the value of the formula.
Because the answer may be very large, please output the answer modulo 1 0 9 + 7 10^9+7 109+7.

输入样例

3 1 3
56
5
20

输出样例

139615686
4017
11554723

题面分析

设 g c d ( a 1 , a 2 , . . . a x ) = d gcd(a_1,a_2,...a_x)=d gcd(a1​,a2​,...ax​)=d,得
∑ a 1 = 1 n ∑ a 2 = 1 n . . . ∑ a x = 1 n ( ∏ j = 1 x a j k ) f ( d ) ∗ d [ g c d ( a 1 , a 2 , . . . a x ) = d ] \sum_{a_1=1}^{n}\sum_{a_2=1}^{n}...\sum_{a_x=1}^{n}(\prod_{j=1}^{x}a_{j}^{k})f(d)*d[gcd(a_1,a_2,...a_x)=d] ∑a1​=1n​∑a2​=1n​...∑ax​=1n​(∏j=1x​ajk​)f(d)∗d[gcd(a1​,a2​,...ax​)=d]
枚举 d d d,得到
∑ d = 1 n d ∗ f ( d ) ∗ ∑ a 1 = 1 n ∑ a 2 = 1 n . . . ∑ a x = 1 n ( ∏ j = 1 x a j k ) [ g c d ( a 1 , a 2 , . . . a x ) = d ] \sum_{d=1}^{n}d*f(d)*\sum_{a_1=1}^{n}\sum_{a_2=1}^{n}...\sum_{a_x=1}^{n}(\prod_{j=1}^{x}a_{j}^{k})[gcd(a_1,a_2,...a_x)=d] ∑d=1n​d∗f(d)∗∑a1​=1n​∑a2​=1n​...∑ax​=1n​(∏j=1x​ajk​)[gcd(a1​,a2​,...ax​)=d]
∑ d = 1 n d k x + 1 ∗ f ( d ) ∗ ∑ a 1 = 1 ⌊ n d ⌋ ∑ a 2 = 1 ⌊ n d ⌋ . . . ∑ a x = 1 ⌊ n d ⌋ ( ∏ j = 1 x a j k ) [ g c d ( a 1 , a 2 , . . . a x ) = 1 ] \sum_{d=1}^{n}d^{kx+1}*f(d)*\sum_{a_1=1}^{\lfloor \frac{n}{d}\rfloor}\sum_{a_2=1}^{\lfloor \frac{n}{d}\rfloor}...\sum_{a_x=1}^{\lfloor \frac{n}{d}\rfloor}(\prod_{j=1}^{x}a_{j}^{k})[gcd(a_1,a_2,...a_x)=1] ∑d=1n​dkx+1∗f(d)∗∑a1​=1⌊dn​⌋​∑a2​=1⌊dn​⌋​...∑ax​=1⌊dn​⌋​(∏j=1x​ajk​)[gcd(a1​,a2​,...ax​)=1]
将 [ g c d ( a 1 , a 2 , . . . a x ) = 1 ] [gcd(a_1,a_2,...a_x)=1] [gcd(a1​,a2​,...ax​)=1]化作 μ \mu μ,得到
∑ d = 1 n d k x + 1 ∗ f ( d ) ∗ ∑ a 1 = 1 ⌊ n d ⌋ ∑ a 2 = 1 ⌊ n d ⌋ . . . ∑ a x = 1 ⌊ n d ⌋ ( ∏ j = 1 x a j k ) ∑ t ∣ a 1 , t ∣ a 2 , . . . t ∣ a x μ ( t ) \sum_{d=1}^{n}d^{kx+1}*f(d)*\sum_{a_1=1}^{\lfloor \frac{n}{d}\rfloor}\sum_{a_2=1}^{\lfloor \frac{n}{d}\rfloor}...\sum_{a_x=1}^{\lfloor \frac{n}{d}\rfloor}(\prod_{j=1}^{x}a_{j}^{k})\sum_{t|a_1,t|a_2,...t|a_x}\mu(t) ∑d=1n​dkx+1∗f(d)∗∑a1​=1⌊dn​⌋​∑a2​=1⌊dn​⌋​...∑ax​=1⌊dn​⌋​(∏j=1x​ajk​)∑t∣a1​,t∣a2​,...t∣ax​​μ(t)
∑ d = 1 n d k x + 1 ∗ f ( d ) ∗ ( ∑ i = 1 ⌊ n d ⌋ i k ) x ∗ ∑ t ∣ a 1 , t ∣ a 2 , . . . t ∣ a x μ ( t ) \sum_{d=1}^{n}d^{kx+1}*f(d)*(\sum_{i=1}^{\lfloor \frac{n}{d}\rfloor}i^k)^x*\sum_{t|a_1,t|a_2,...t|a_x}\mu(t) ∑d=1n​dkx+1∗f(d)∗(∑i=1⌊dn​⌋​ik)x∗∑t∣a1​,t∣a2​,...t∣ax​​μ(t)
枚举 t t t得
∑ d = 1 n d k x + 1 ∗ t k x ∗ f ( d ) ∗ ∑ t = 1 ⌊ n d ⌋ μ ( t ) ( ∑ i = 1 ⌊ n d t ⌋ i k ) x \sum_{d=1}^{n}d^{kx+1}*t^{kx}*f(d)*\sum_{t=1}^{\lfloor \frac{n}{d}\rfloor}\mu(t)(\sum_{i=1}^{\lfloor \frac{n}{dt}\rfloor}i^k)^x ∑d=1n​dkx+1∗tkx∗f(d)∗∑t=1⌊dn​⌋​μ(t)(∑i=1⌊dtn​⌋​ik)x
设 T = t d T=td T=td,得到
∑ T = 1 n T k x d f ( d ) ∗ ( ∑ i = 1 ⌊ n T ⌋ i k ) x ∗ ∑ t ∣ T μ ( t ) \sum_{T=1}^{n}T^{kx}df(d)*(\sum_{i=1}^{\lfloor \frac{n}{T}\rfloor}i^k)^x*\sum_{t|T}\mu(t) ∑T=1n​Tkxdf(d)∗(∑i=1⌊Tn​⌋​ik)x∗∑t∣T​μ(t)
为了方便计算,我们把右边的 t ∣ T t|T t∣T改成 d ∣ T d|T d∣T,得到
∑ T = 1 n T k x ( ∑ i = 1 ⌊ n T ⌋ i k ) x ∗ ∑ d ∣ T μ ( d ) d f ( T d ) \sum_{T=1}^{n}T^{kx}(\sum_{i=1}^{\lfloor \frac{n}{T}\rfloor}i^k)^x*\sum_{d|T}\mu(d)df(\frac{T}{d}) ∑T=1n​Tkx(∑i=1⌊Tn​⌋​ik)x∗∑d∣T​μ(d)df(dT​)
设 G ( x ) = ∑ d ∣ T μ ( d ) d f ( T d ) G(x)=\sum_{d|T}\mu(d)df(\frac{T}{d}) G(x)=∑d∣T​μ(d)df(dT​)
首先 μ \mu μ可以 O ( n ) O(n) O(n)预处理, f f f也可以 O ( n l o g n ) O(nlogn) O(nlogn)预处理
那么G可以在 O ( n ) O(n) O(n)下预处理
对于 ( ∑ i = 1 ⌊ n T ⌋ i k ) x (\sum_{i=1}^{\lfloor \frac{n}{T}\rfloor}i^k)^x (∑i=1⌊Tn​⌋​ik)x,也可以在 O ( n l o g n ) O(nlogn) O(nlogn)下处理完
对于每一次查询,利用分块和预处理前缀和,只需要 O ( n ) O(\sqrt{n}) O(n ​)。
故总复杂度为 O ( n l o g n + T n ) O(nlogn+T\sqrt{n}) O(nlogn+Tn ​)

AC代码(2199ms)

#include <bits/stdc++.h>
using namespace std;
const long long maxn=2e5;
const long long mod=1e9+7;
bool check[maxn+10];//访问标记
int prime[maxn+10];//质数
int mu[maxn+10];//mu函数
int f[maxn+10];//f函数
long long powk[maxn+10];
long long G[maxn+10];
long long sumG[maxn+10];
long long n, k, x;
inline long long quick_pow(long long a, long long b)//快速幂
{long long ans=1, base=a;while(b!=0){if (b&1)ans=(long long) ans*base%mod;base=(long long) base*base%mod;b>>=1;}return ans;
}
void init()
{f[1]=mu[1]=1;int tot=0;for(int i=2; i<=maxn; i++){f[i]=1;if (!check[i]){prime[tot++]=i;mu[i]=-1;}for(int j=0; j<tot; j++){if (i*prime[j]>maxn) break;check[i*prime[j]]=true;if (i%prime[j]==0){mu[i*prime[j]]=0;break;}else{mu[i*prime[j]]=-mu[i];}}}for(long long d=2; d<=maxn; d++)//处理f{for(long long j=d*d; j<=maxn; j+=d*d){f[j]=0;}}G[0]=0;for(long long d=1; d<=maxn; d++)//处理G{for(long long i=d; i<=maxn; i+=d){G[i]=(G[i]+d*f[d]%mod*mu[i/d]%mod+mod)%mod;}}powk[0]=0;sumG[0]=0;for(long long i=1; i<=maxn; i++)//处理累加{long long z=quick_pow(i, k);powk[i]=(powk[i-1]+z)%mod;sumG[i]=(sumG[i-1]+quick_pow(z, x)*G[i]%mod)%mod;}
}
long long answer()
{long long ans=0;for(long long l=1, r; l<=n; l=r+1){r=n/(n/l);ans=(ans+(sumG[r]-sumG[l-1]+mod)%mod*quick_pow(powk[n/l], x)%mod)%mod;}return ans;
}
void solve()
{int t;scanf("%d%lld%lld", &t, &k, &x);init();while(t--){scanf("%lld", &n);printf("%lld\n", answer());}
}
int main()
{//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);
#ifdef ACM_LOCALfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long long test_index_for_debug=1;char acm_local_for_debug;while(cin>>acm_local_for_debug){cin.putback(acm_local_for_debug);if (test_index_for_debug>100){throw runtime_error("Check the stdin!!!");}auto start_clock_for_debug=clock();solve();auto end_clock_for_debug=clock();cout<<"\nTest "<<test_index_for_debug<<" successful"<<endl;cerr<<"Test "<<test_index_for_debug++<<" Run Time: "<<double(end_clock_for_debug-start_clock_for_debug)/CLOCKS_PER_SEC<<"s"<<endl;cout<<"--------------------------------------------------"<<endl;}
#elsesolve();
#endifreturn 0;
}

DrGilbert 2020.8.7

HDU 6833 A Very Easy Math Problem(莫比乌斯反演)相关推荐

  1. 2020杭电多校第六场 A Very Easy Math Problem 莫比乌斯反演 (HDU 6833)

    A Very Easy Math Problem 题解 ∑ a 1 = 1 n ∑ a 2 = 1 n ⋅ ⋅ ⋅ ∑ a x = 1 n ( ∏ j = 1 x a j k ) f ( g c d ...

  2. HDU 6833 A Very Easy Math Problem

    A Very Easy Math Problem 推式子 ∑ai=1n∑a2=1n⋯∑ax=1n(∏j=1xajk)f(gcd(a1,a2,-,ax))×gcd(a1,a2,-,ax)\sum_{a_ ...

  3. HDU 6607 Easy Math Problem(杜教筛 + min_25 + 拉格朗日插值)

    Easy Math Problem 推式子 ∑i=1n∑j=1ngcd(i,j)Klcm(i,j)[gcd(i,j)∈prime]∑i=1n∑j=1ngcd(i,j)K−1ij[gcd(i,j)∈pr ...

  4. BZOJ3309 DZY Loves Math(莫比乌斯反演+线性筛)

    一通正常的莫比乌斯反演后,我们只需要求出g(n)=Σf(d)*μ(n/d)的前缀和就好了. 考虑怎么求g(n).当然是打表啊.设n=∏piai,n/d=∏pibi .显然若存在bi>1则这个d没 ...

  5. 【HDU - 1757】A Simple Math Problem (矩阵快速幂)

    题干: Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.  If x >= 10 f(x) = ...

  6. hdu 1757【A Simple Math Problem】

    矩阵相乘 代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 struct matrix 5 { 6 int g[10][10 ...

  7. [HDU6833]A Very Easy Math Problem

    题意 求 ∑ a 1 = 1 n ∑ a 2 = 1 n ⋯ ∑ a x = 1 n ( ∏ j = 1 x a j k ) f ( gcd ⁡ ( a 1 , a 2 , . . . , a x ) ...

  8. Bzoj3309-DZY Loves Math【莫比乌斯反演,线性筛】

    正题 bzoj没了,在darkbzoj交吧 题目链接:https://darkbzoj.tk/problem/3309 题目大意 定义f(x)f(x)f(x)表示xxx所有质因数中最大的指数幂. 求∑ ...

  9. HYSBZ - 3309 D - DZY Loves Math(莫比乌斯反演+组合思想+DP思想)*好题。。。

    题目链接:https://cn.vjudge.net/problem/HYSBZ-3309 #include<bits/stdc++.h> using namespace std;#def ...

最新文章

  1. 中国批准AMD收购赛灵思!苏妈花350亿美元集齐CPU\GPU\FPGA三大芯片业务
  2. 垃圾回收机制与引用类型
  3. 【原创】MapReduce编程系列之表连接
  4. vue 分模块打包 脚手架_Vue面试官最爱的底层源码问题,你可以这样回答!
  5. c语言结果输出10遍,C语言 如何实现输出这样一系列输出结果
  6. Matlab程序怎样打包
  7. NOI2018 Day1 归程(Kruskal重构树)
  8. 图像处理VintaSoftImaging.NET SDK控件发布v7.0版本
  9. 信号怎么用matlab分类,使用迁移学习做信号分类
  10. c语言 素数环,C语言素数环 DFS +回溯
  11. Win11 安卓子系统 (WSA) 安装包教程 - 电脑运行 Android 手机应用 / 安装 APK 方法
  12. SaaSpace:11个免费建筑信息建模软件工具
  13. L型与R型思维的特征
  14. 3.4 Postman调用手顺(Netsuite相关)
  15. js插件--1.swal
  16. android烤机按键变慢,Android8.0平台Camera monkey拷机卡死异常
  17. 笔记本电脑移动到行尾 行首 快捷键
  18. C语言中的atoi函数的实现
  19. 抖音直播带货怎么选品?抖音直播选品的方法和技巧有哪些呢?
  20. 开源ERP Tryton 的用户权限管理

热门文章

  1. 【码蹄集新手村 600 题】用符号输出一个沙漏的图像
  2. Laravel表格操作Laravel-Excel
  3. 智课雅思短语---四、Exploit to the full one’s favorableconditions and avoid unfavorable ones...
  4. 植物大战僵尸2 服务器维护时间,限时活动上线《植物大战僵尸2》V2.2.3即日更新!...
  5. 检核表法(创新思维3)
  6. 计算机英语会话实用电脑英语,实用计算机英语
  7. 如何进行数据可视化图表设计?
  8. Java期末作业——王者荣耀的洛克王国版游戏
  9. Java多线程系列之“JUC集合“详解
  10. C/C++学生选课管理系统[2023-02-20]