2019南昌网络赛G. tsy's number
题意:\(\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^n\frac{\phi(i)*\phi(j^2)*\phi(k^3)}{\phi(i)*\phi(j)*\phi(k)}\phi(gcd(i,j,k))\),1e4组询问,每次给\(n(1<=n<=1e7)\).
题解:由\(\phi(x)\)的性质\(x=p_1^{k_1}*p_2^{k_2}*...*p_n^{k_n}\),\(\phi(x)=p_1^{k_1-1}*(p_1-1)*p_2^{k_2-1}*(p_2-1)...*p_n^{k_n-1}*(p_n-1)\),\(\phi(x^2)=p_1^{2*k_1-1}*(p_1-1)*p_2^{2*k_2-1}*(p_2-1)...*p_n^{2*k_n-1}*(p_n-1)\).
\(\phi(x^2)=x*\phi(x)\).
\(\phi(x^3)=x^2*\phi(x)\).
原式化为:
\(\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^nj*k^2*\phi(gcd(i,j,k))\)
\(=\sum_{d=1}^n\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^nj*k^2*\phi(d)[gcd(i,j,k)==d]\)
\(=\sum_{d=1}^n\phi(d)\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^nj*k^2*[gcd(i,j,k)==d]\)
设\(f(n)=\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^nj*k^2*[gcd(i,j,k)==d]\).
\(F(n)=\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^nj*k^2*[d|gcd(i,j,k)]\)
\(F(n)=d^3*\sum_{i=1}^{\left \lfloor \frac{n}{d} \right \rfloor}\sum_{j=1}^{\left \lfloor \frac{n}{d} \right \rfloor}j\sum_{k=1}^{\left \lfloor \frac{n}{d} \right \rfloor}k^2\)
\(F(n)=d^3*\frac{{\left \lfloor \frac{n}{d} \right \rfloor}^3*({\left \lfloor \frac{n}{d} \right \rfloor}+1)^2*({\left \lfloor \frac{n}{d} \right \rfloor}*2+1)}{12}\)
由莫比乌斯反演
\(f(n)=\sum_{x=1}^{{\left \lfloor \frac{n}{d} \right \rfloor}}\mu(x)*(d*x)^3*\frac{{\left \lfloor \frac{n}{d*x} \right \rfloor}^3*({\left \lfloor \frac{n}{d*x} \right \rfloor}+1)^2*({\left \lfloor \frac{n}{d*x} \right \rfloor}*2+1)}{12}\)
原式化为:
\(\sum_{d=1}^n\phi(d)*\sum_{x=1}^{{\left \lfloor \frac{n}{d} \right \rfloor}}\mu(x)*(d*x)^3*\frac{{\left \lfloor \frac{n}{d*x} \right \rfloor}^3*({\left \lfloor \frac{n}{d*x} \right \rfloor}+1)^2*({\left \lfloor \frac{n}{d*x} \right \rfloor}*2+1)}{12}\)
\(=\sum_{t=1}(t)^3*\frac{{\left \lfloor \frac{n}{t} \right \rfloor}^3*({\left \lfloor \frac{n}{t} \right \rfloor}+1)^2*({\left \lfloor \frac{n}{t} \right \rfloor}*2+1)}{12}\sum_{d|t}\phi(d)*\mu(\frac{t}{d})\)
假设\(g(n)=\sum_{d|n}\phi(d)*\mu(\frac{n}{d})\),g是积性函数,考虑线筛求g,只需考虑递推求\(g(p^k)\)
\(g(p^k)=\sum_{i=0}^k\phi(p^i)*\mu(p^{k-i})\)
由莫比乌斯函数性质\(g(p^k)=phi(p^k)*\mu(1)+phi(p^{k-1})*\mu(p)=\phi(p^k)-\phi(p^{k-1})\)
当\(k==1\)时\(g(p)=p-2\).
当\(k!=1\)时\(g(p^k)=p^{k-2}*(p-1)^2\)
线筛求g,之后和\(i^3\)一起求前缀和,然后每次询问分块即可
注意模数是\(2^{30}\)没法直接求12的逆元,要先除去4再求3和模数的逆元(扩展gcd)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1073741824
#define ld long double
//#define C 0.5772156649
//#define ls l,m,rt<<1
//#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}
using namespace std;
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=10000000+10,maxn=1000000+10,inf=0x3f3f3f3f;
ll f[N];
int prime[N],cnt,num[N];
bool mark[N];
void init()
{
f[1]=1;
for(int i=2;i<N;i++)
{
if(!mark[i])prime[++cnt]=i,f[i]=i-2,num[i]=1;
for(int j=1;j<=cnt&&i*prime[j]<N;j++)
{
mark[i*prime[j]]=1;
if(i%prime[j]==0)
{
num[i*prime[j]]=num[i]+1;
if(num[i]==1)
{
if(prime[j]==2)f[i*prime[j]]=f[i/prime[j]];
else f[i*prime[j]]=f[i]/(prime[j]-2)*(prime[j]-1)*(prime[j]-1);
}
else f[i*prime[j]]=f[i]*prime[j];
break;
}
f[i*prime[j]]=f[i]*f[prime[j]];
num[i*prime[j]]=1;
}
}
for(int i=1;i<N;i++)
f[i]=(f[i-1]+f[i]*i%mod*i%mod*i%mod)%mod;
}
int main()
{
ll gan=715827883;
init();
int T;scanf("%d",&T);
while(T--)
{
int n;scanf("%d",&n);
ll ans=0;
for(int i=1,j;i<=n;i=j+1)
{
j=n/(n/i);
ll te=n/i,pp=(f[j]-f[i-1]+mod)%mod;
if(te%2==0)
{
add(ans,(te/2)*(te/2)%mod*te%mod*(te+1)%mod*(te+1)%mod*(te*2+1)%mod*pp%mod*gan%mod);
}
else
{
add(ans,te*te%mod*te%mod*((te+1)/2)%mod*((te+1)/2)%mod*(te*2+1)%mod*pp%mod*gan%mod);
}
}
printf("%lld\n",ans);
}
return 0;
}
/********************
********************/
2019南昌网络赛G. tsy's number的更多相关文章
- 2019南昌网络赛I:Yukino With Subinterval(CDQ) (树状数组套主席树)
题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点, ...
- ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval
ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- 2019南昌网络赛 hello 2019
这道题和一道2017,2016的类似. A string t is called nice if a string “2017” occurs in t as a subsequence but a ...
- 2019南昌网络赛 I. Yukino With Subinterval 树状数组套线段树
I. Yukino With Subinterval 题目链接: Problem Descripe Yukino has an array \(a_1, a_2 \cdots a_n\). As a ...
- 2019南昌网络赛 J Distance on the tree 主席树+lca
题意 给一颗树,每条边有边权,每次询问\(u\)到\(v\)的路径中有多少边的边权小于等于\(k\) 分析 在树的每个点上建\(1\)到\(i\)的权值线段树,查询的时候同时跑\(u,v,lca ...
- 2019 徐州网络赛 G Colorful String 回文树
题目链接:https://nanti.jisuanke.com/t/41389 The value of a string sss is equal to the number of differen ...
- 2019南昌网络赛-I(单调栈+线段树)
题目链接:https://nanti.jisuanke.com/t/38228 题意:定义一段区间的值为该区间的和×该区间的最小值,求给定数组的最大的区间值. 思路:比赛时还不会线段树,和队友在这题上 ...
- 2019南昌网络赛-M(二分)
题目链接:https://nanti.jisuanke.com/t/38232 题意:给定字符串s(长度<=1e5),然后N组样例(N<=1e5),每组输入一个字符串t判断t是否为s的字串 ...
随机推荐
- Python多维数组切片
1. array如果维度多了,就变成ndarray. 2. list切片类似C数组,多维度分别用”[]“索引,单维度切片用”:“,如: >>> a [[1, 2, 3], [4, 5 ...
- <转载>XML操作
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- 【论文速读】Lianwen_Jin_CVPR2017_Deep_Matching_Prior_Network_Toward_Tighter_Multi-oriented_Text_Detection
Lianwen_Jin_CVPR2017_Deep_Matching_Prior_Network_Toward_Tighter_Multi-oriented_Text_Detection 作者 关键词 ...
- sql sugar
事务 using (var db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.xxx, DbType ...
- 第一个SDL程序
不废话,就WinMain主体: SDL_Window* window = NULL; SDL_Renderer* renderer = NULL; SDL_Event e; bool q = 0; i ...
- ldap认证jupyter notebook
虽然jupyter hub是支持ldap的,见ldapauthenticator: 但是登录成功后似乎要以登录用户名启动notebook,而登录用户在服务器上不存在,于是500了: 在服务器上通过pa ...
- 宝塔安装swoole
新建文件夹 mkdir swoole 切入到文件夹中,进行下载安装包 wget http://pecl.php.net/get/swoole-4.3.2.tgz 解压 tar -zxvf swoole ...
- mySQL简单操作(一)
推荐学习网站(https://sqlzoo.net/wiki/SQL_Tutorial) 1.创建mSQL数据表(表名,表字段名,定义表字段) create table tbl_name [if no ...
- CentOS7 安装极点五笔输入法
下载并解压vissible-ibus.tar.gz 或者这个vissible-ibus.tar.gz cp vissible.db /usr/share/ibus-table/tables/ cp v ...
- Elasticsearch-搭建自己的搜索系统
参考链接: https://blog.csdn.net/weixin_42730079/article/details/81113806 https://www.cnblogs.com/dreamro ...