SP1772 Find The Determinant II
题意
\(T\) 组数据,每组给定两个整数 \(n,k\),求 \(\det A\),其中 \(A\) 为一个 \(n\times n\) 的矩阵且 \(A_{i,j}=\gcd(i,j)^k\),对 \(10^6+3\) 取模。
\(\texttt{Data Range:}1\leq T\leq 20,1\leq n\leq 10^6,1\leq k\leq 10^9\)
题解
很好的一道数论题。(然而可能只是因为我出过一道相似的)
类似于这个题的思路,设 \(f_{i}\) 为消元后 \(A_{i,i}\) 的值,我们有
\]
移项得到
\]
这个式子跟 \(\varphi(n)\) 的狄利克雷卷积式有些类似,我们考虑狄利克雷生成函数求通项。为了不失普遍性,我们记消元之后的 \(f(n)=\varphi_k(n)\)。(这个东西其实叫 Jordan totient function,符号为 \(J_k(n)\),但是为了体现出类比所以我选用这个符号)
套个 \(\sum\) 我们有
\]
移项有
\]
使用欧拉乘积公式化开右边(其中 \(P\) 是素数集)
\]
这里有一个定理:如果 \(g_n\) 存在积性,那么可以将 \(g_n\) 对应的狄利克雷生成函数写成如下形式
\]
发现之前式子的右边很像这个东西,所以右边写成这个形式有
\]
所以我们知道 \(\varphi_k(i)\) 是积性函数,也知道在 \(p^k\) 处的取值,所以有:
\]
线性筛出这东西即可,答案为 \(\prod\limits_{i=1}^{n}\varphi_k(i)\),时间复杂度 \(O(Tn)\)。
交 SPOJ 的题是可以正常开 pragma 的
代码
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=1e6+51,MOD=1e6+3;
ll test,n,kk,ptot,res;
ll np[MAXN],prime[MAXN],phi[MAXN],pwPr[MAXN];
inline ll read()
{
register ll num=0,neg=1;
register char ch=getchar();
while(!isdigit(ch)&&ch!='-')
{
ch=getchar();
}
if(ch=='-')
{
neg=-1;
ch=getchar();
}
while(isdigit(ch))
{
num=(num<<3)+(num<<1)+(ch-'0');
ch=getchar();
}
return num*neg;
}
inline ll qpow(ll base,ll exponent)
{
ll res=1;
while(exponent)
{
if(exponent&1)
{
res=(li)res*base%MOD;
}
base=(li)base*base%MOD,exponent>>=1;
}
return res;
}
inline void sieve(ll limit)
{
np[1]=phi[1]=1,ptot=0;
for(register int i=2;i<=limit;i++)
{
if(!np[i])
{
prime[++ptot]=i,phi[i]=(pwPr[i]=qpow(i,kk))-1;
}
for(register int j=1;i*prime[j]<=limit;j++)
{
np[i*prime[j]]=1;
if(i%prime[j]==0)
{
phi[i*prime[j]]=(li)phi[i]*pwPr[prime[j]]%MOD;
break;
}
phi[i*prime[j]]=(li)phi[i]*phi[prime[j]]%MOD;
}
}
}
inline void solve()
{
n=read(),kk=read()%(MOD-1),sieve(n),res=1;
for(register int i=1;i<=n;i++)
{
res=(li)res*phi[i]%MOD;
}
printf("%d\n",res);
}
int main()
{
test=read();
for(register int i=0;i<test;i++)
{
solve();
}
}
SP1772 Find The Determinant II的更多相关文章
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II
题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...
- 函数式Android编程(II):Kotlin语言的集合操作
原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...
- 统计分析中Type I Error与Type II Error的区别
统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- [LeetCode] Number of Islands II 岛屿的数量之二
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
随机推荐
- spring初始(介绍、核心架构)
1.spring介绍 Spring是个java企业级应用的开源开发框架.主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用.Spring框架目标是简化Java企业级应用开发,并通 ...
- Oracle 11gR2-Win 64bit
版本:Oracle 11gR2下载地址:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.ht ...
- 如何让百度网盘下载速度达60MB/s!
(软件下载方式在文末) 自从 PanDownload 被处理之后 一直没有超越它的可替代的应用出来 但是最近,竟然有人接盘了!重新制作上线 推出了更加强劲的复活版! 放张图,大家先感受下 60MB/s ...
- 前端gitlab-ci.yml 入门
说起来使用gitlab也有大半年了,每天都在跑pipeline,但是却没有好好研究过这个叫gitlab-ci.yml的文件.这次借着发布流程升级的机会,好好入门了一下. 主要分以下内容: stages ...
- CF471D MUH and Cube Walls
Link 一句话题意: 给两堵墙.问 \(a\) 墙中与 \(b\) 墙顶部形状相同的区间有多少个. 这生草翻译不想多说了. 我们先来转化一下问题.对于一堵墙他的向下延伸的高度,我们是不用管的. 我们 ...
- [源码阅读] 阿里SOFA服务注册中心MetaServer(1)
[源码阅读] 阿里SOFA服务注册中心MetaServer(1) 目录 [源码阅读] 阿里SOFA服务注册中心MetaServer(1) 0x00 摘要 0x01 服务注册中心 1.1 服务注册中心简 ...
- Centos7 Docker配置TLS认证的远程端口的证书生成教程(shell脚本一键生成)
通过 TLS来进行远程访问 百度百科 - TLS.我们需要在远程 docker 服务器(运行 docker 守护进程的服务器)生成 CA 证书,服务器证书,服务器密钥,然后自签名,再颁发给需要连接远程 ...
- pytest文档50-命令行参数--durations统计用例运行时间
前言 写完一个项目的自动化用例之后,发现有些用例运行较慢,影响整体的用例运行速度,于是领导说找出运行慢的那几个用例优化下. --durations 参数可以统计出每个用例运行的时间,对用例的时间做个排 ...
- docker registry 记录
部署 运行下面命令获取registry镜像 docker pull registry 下载到的版本默认为 docker.io/registry latest 将registry镜像运行并生成一个容器 ...
- 【树形DP】BZOJ 3829 Farmcraft
题目内容 mhy住在一棵有n个点的树的1号结点上,每个结点上都有一个妹子i. mhy从自己家出发,去给每一个妹子都送一台电脑,每个妹子拿到电脑后就会开始安装zhx牌杀毒软件,第i个妹子安装时间为Ci. ...