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 ...
随机推荐
- Generator函数在流程控制中的应用
扯蛋 做了两年的Nodejs全栈开发,不知道为什么跑来做游戏呢(大概是厦门nodejs不好找工作吧).用的是网易的pomelo的游戏框架.现接手了一个棋牌游戏:二十一点,不懂的规则的可以自行百度. 二 ...
- Python练习题 034:Project Euler 006:和平方与平方和之差
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...
- 【SCOI2016】背单词
P3294[SCOI2016]背单词 [提示] 这道题大概是告诉我们,让我们用一堆n个单词安排顺序,如果当前位置为x,当前单词的后缀没在这堆单词出现过,代价就为x,这里的后缀是原意,但不算自己(不算本 ...
- [JZOJ]2109 清兵线 题解
## [JZOJ]2109 清兵线 题解 **FIRST 题目大意** 给你一些正整数,这些正整数为数轴上若干个点代表的数.现求:假设从原点出发,走m以内(包括m)的距离最多能够访问多少个点,输出m- ...
- SQL错题集
查找最晚入职员工的所有信息 select * from employees where hire_date = (select max(hire_date) from employees) 查找入职员 ...
- Python如何安装OpenCV库
转载:https://blog.csdn.net/weixin_35684521/article/details/81953047 OpenCV的概念可百度,在此不再赘述.https://baike. ...
- 《C++primerplus》第9章练习题
1.(未使用原书例题)练习多文件组织.在一个头文件中定义一种学生的结构体,存储姓名和年龄,声明三个函数分别用于询问有多少个学生,输入学生的信息和展示学生的信息.在另一个源文件中给出所有函数的定义.在主 ...
- 浅谈 Java集合
Java 集合 集合是对象的容器,定义了多个对象进行操作的常用方法,可实现数组的功能. Java集合类库所处位置:java.util.*. 与现代的数据结构类库的常见做法一样,Java集合类库也将接口 ...
- jquery购物车全选,取消全选,计算总金额
这是html代码 <div class="gwcxqbj"> <div class="gwcxd center"> <div cl ...
- FRP服务
FRP服务 - Web服务 本服务提供Web内网穿透服务,并且开放端口 443和 80端口. 写在前面:提供公益FRP服务器:frp.dev.boselor.com,服务器在洛杉矶但是请勿用于违法用途 ...