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 ...
随机推荐
- 最精美详尽的 HTTPS 原理图!
来源:r6a.cn/ffJk 作为一个有追求的程序员,了解行业发展趋势和扩充自己的计算机知识储备都是很有必要的,特别是一些计算机基础方面的内容,就比如本篇文章要讲的计算机网络方面的知识.本文将为大 ...
- Go-The process cannot access the file because it is being used by another process.
where? Go程序在读取文件时候 why? 因为有其他进程也在读取和Go程序想要读取的文件,参数冲突 way? 关闭其他程序进程对该文件的读取操作
- 054 01 Android 零基础入门 01 Java基础语法 06 Java一维数组 01 数组概述
054 01 Android 零基础入门 01 Java基础语法 06 Java一维数组 01 数组概述 本文知识点:数组概述 为什么要学习数组? 实际问题: 比如我们要对学生的成绩进行排序,一个班级 ...
- matlab中axis的用法
来源:https://ww2.mathworks.cn/help/matlab/ref/axis.html?searchHighlight=axis&s_tid=doc_srchtitle a ...
- tuple的增删改查
dict = {"k1": "v1", "k2": "v2", "k3": "v3&quo ...
- Selenium截屏 图片未加载的问题解决--【懒加载】
需求: 截屏后转PDF. 问题: selenium截屏后,图片未加载 如下图: 原因: 网站使用了懒加载技术:只有在浏览器中纵向滚动条滚动到指定的位置时,页面的元素才会被动态加载. 什么是图片懒加载? ...
- 利用 Python 插入 Oracle 数据
# coding=utf-8 ''''' Created on 2020-01-05 @author: Mr. Zheng ''' import json; import urllib2 import ...
- linux的安装3.7python
centos安装python3 首先安装依赖包 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-dev ...
- 在nginx下导出数据库数据
首先上干货 解决问题 set_time_limit(0); //设置脚本运行时间为不限制 因为php脚本默认时间为30秒 ini_set('memory_limit', -1); //取消脚本运行内存 ...
- 有感于“U盘型人才”
先转载一篇互联网上转载比较多的一篇文章,文章是一名职业规划师写的: 上一阶段欠的债,下一阶段总要还,剩男剩女的家里比较着急也是这个道理,该结婚的时候不结婚,生涯任务没完成,必将影响下一段 ...