题意

\(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}\) 的值,我们有

\[f_n=n^k-\sum\limits_{d\mid n,d<n}f_d
\]

移项得到

\[n^k=\sum\limits_{d\mid n}f_d
\]

这个式子跟 \(\varphi(n)\) 的狄利克雷卷积式有些类似,我们考虑狄利克雷生成函数求通项。为了不失普遍性,我们记消元之后的 \(f(n)=\varphi_k(n)\)。(这个东西其实叫 Jordan totient function,符号为 \(J_k(n)\),但是为了体现出类比所以我选用这个符号)

套个 \(\sum\) 我们有

\[\sum\limits_{i\geq 1}\frac{i^k}{i^x}=\zeta(x)\sum\limits_{i\geq 1}\frac{\varphi_k(i)}{i^x}
\]

移项有

\[\sum\limits_{i\geq 1}\frac{\varphi_k(i)}{i^x}=\frac{\zeta(x-k)}{\zeta(x)}
\]

使用欧拉乘积公式化开右边(其中 \(P\) 是素数集)

\[\sum\limits_{i\geq 1}\frac{\varphi_k(i)}{i^x}=\prod_{p\in P}\frac{1-p^{-x}}{1-p^{k-x}}
\]

这里有一个定理:如果 \(g_n\) 存在积性,那么可以将 \(g_n\) 对应的狄利克雷生成函数写成如下形式

\[G(x)=\prod_{p\in P}\left(\sum_{i}\frac{g_{p^i}}{p^{ix}}\right)
\]

发现之前式子的右边很像这个东西,所以右边写成这个形式有

\[\sum\limits_{i\geq 1}\frac{\varphi_k(i)}{i^x}=\prod_{p\in P}\left(\sum_{i}\frac{p^{ik}-p^{(i-1)k}}{p^{ix}}\right)
\]

所以我们知道 \(\varphi_k(i)\) 是积性函数,也知道在 \(p^k\) 处的取值,所以有:

\[\varphi_k(n)=n^k\prod_{i=1}^{m}\frac{p_i^k-1}{p_i^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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 函数式Android编程(II):Kotlin语言的集合操作

    原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...

  4. 统计分析中Type I Error与Type II Error的区别

    统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...

  5. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  6. [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 ...

  7. [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 ...

  8. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  9. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

随机推荐

  1. Vue 组件的基础介绍

    1.组件定义 1.定义组件并引用 2.父组件向子组件传值 3.子组件向父组件传值 # 组件间传值:vuex (https://www.cnblogs.com/xiaonq/p/9697921.html ...

  2. Python-in is == 区别

    in 判断单个元素是否在序列中, 对字典来说只能判断key,在不在关系 print("ab" in "abcdefg") print("abc&quo ...

  3. FastReport.Mono添加了新的条形码ITF-14

    FastReport.Mono 是一款为Mono Framework设计的功能全面的报表生成工具.FastReport.Mono 是一个多平台的报表解决方法.它可以应用于Windows, Linux, ...

  4. Java知识系统回顾整理01基础04操作符01算术操作符

    一.算数操作符类别 基本的有: + - * / % 自增 自减: ++ -- 二.基本算数操作符 + - * / 基本的加 减 乘 除 public class HelloWorld { public ...

  5. OpenCV计算机视觉学习(2)——图像算术运算 & 掩膜mask操作(数值计算,图像融合,边界填充)

    在OpenCV中我们经常会遇到一个名字:Mask(掩膜).很多函数都使用到它,那么这个Mask到底是什么呢,下面我们从图像基本运算开始,一步一步学习掩膜. 1,图像算术运算 图像的算术运算有很多种,比 ...

  6. C# Dropdownlist设置选择项

    (1)   dropdowslist.selectedIndex=索引值(数字); (2) dropdownlist.Items.findbyvalue(你的值).selected=true   (3 ...

  7. Navicat连接MySQL报错-2059

    解释原因:据说,mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password, 解决问题方法有两种,一种是 ...

  8. 一、Mysql(1)

    数据库简介 人类在进化的过程中,创造了数字.文字.符号等来进行数据的记录,但是承受着认知能力和创造能力的提升,数据量越来越大,对于数据的记录和准确查找,成为了一个重大难题 计算机诞生后,数据开始在计算 ...

  9. [KMP]字符串匹配算法

    算法介绍: KMP是一种用来处理字符串匹配问题的算法,给你两个字符串A.B,让你回答B是否为A的子串,或者A中有多少子串等于B. 这题最暴力的做法是:枚举A中与B相等的子串的左端点,再判断是否与B相等 ...

  10. Varnish 6.2.2 的介绍与安装

    一.简介 Varnish 是一款高性能且开源的反向代理服务器和 HTTP 加速器,其采用全新的软件体系机构,和现在的硬件体系紧密配合,与传统的 Squid 相比,Varnish 具有性能更高.速度更快 ...