HZOI20190823 C magic
数论板子合集。。。
我们要求:
$N^{\sum\limits_{i=1}^{N}[gcd(i,N)==1]C_{n}^{i}}mod p$
其中p为54184622,是个合数
指数是组合数,不能用快速幂,只能mod phi(p),phi(p)=p-1,而p-1不是质数,要用crt合并
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#define mod 54184622
#define int long long
#define MAXN 1000005
using namespace std;
int n,g,a[7],prime[7]={0,2,3,5,7,129011};
int fac[7][MAXN],ans;
int q_pow(int a,int b,int p){
int res=1;
while(b){
if(b&1) res=(res*a)%p;
a=(a*a)%p;
b>>=1;
}
return res%p;
}
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
int C(int n,int m,int p){
if(n==m) return 1;
if(m>n) return 0;
return fac[p][n]*q_pow(fac[p][m]*fac[p][n-m]%prime[p],prime[p]-2,prime[p]);
}
int lucas(int n,int m,int p){
if(m==0) return 1;
return lucas(n/prime[p],m/prime[p],p)%mod*C(n%prime[p],m%prime[p],p)%prime[p];
}
int crt(){
int p=27092310,res=0;
for(int i=1;i<=5;i++)
res=(res+p/prime[i]*a[i]%p*q_pow(p/prime[i],prime[i]-2,prime[i])%p)%p;
return res;
}
signed main(){
scanf("%lld %lld",&n,&g);
for(int i=1;i<=5;i++){
fac[i][0]=1;
for(int j=1;j<=prime[i];j++)
fac[i][j]=fac[i][j-1]*j%prime[i];
}
for(int i=1;i<=min(n,g);i++){
if(gcd(i,n)!=1) continue;
for(int j=1;j<=5;j++){
a[j]=(a[j]+lucas(g,i,j))%prime[j];
}
}
ans=crt();
printf("%lld\n",q_pow(n,ans,mod));
return 0;
}
HZOI20190823 C magic的更多相关文章
- Codeforces CF#628 Education 8 D. Magic Numbers
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- [8.3] Magic Index
A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted ar ...
- Python魔术方法-Magic Method
介绍 在Python中,所有以"__"双下划线包起来的方法,都统称为"Magic Method",例如类的初始化方法 __init__ ,Python中所有的魔 ...
- 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律
F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...
- 一个快速double转int的方法(利用magic number)
代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...
- MAGIC XPA最新版本Magic xpa 2.4c Release Notes
New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...
- Magic xpa 2.5发布 Magic xpa 2.5 Release Notes
Magic xpa 2.5發佈 Magic xpa 2.5 Release Notes Magic xpa 2.5 Release NotesNew Features, Feature Enhance ...
- How Spring Boot Autoconfiguration Magic Works--转
原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...
随机推荐
- Git中.gitignore忽略规则
# 此为注释 – 将被 Git 忽略 *.a # 忽略所有 .a 结尾的文件 !lib.a # 但 lib.a 除外 /TODO # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TO ...
- 驱动层hook系统函数的时,如何屏蔽掉只读属性?
对于Intel 80486或以上的CPU,CR0的位16是写保护(Write Proctect)标志.当设置该标志时,处理器会禁止超级用户程序(例如特权级0的程序)向只读页面执行写操作:当该位复位时则 ...
- VS2010-MFC(对话框:文件对话框)
转自:http://www.jizhuomi.com/software/173.html 一 文件对话框的分类 文件对话框分为打开文件对话框和保存文件对话框,相信大家在Windows系统中 ...
- PHP面向对象编程题(方法的实践)
<?php header('content-type:text/html;charset=utf-8'); /*设计一个peron类(有名字,年龄和蛋糕三个属性) 蛋糕一共1000块,是所有人共 ...
- Java工具之NotePad++使用技巧
按住Alt键 拖动鼠标左键 批量添加 如,等 批量添加逗号, 下面, 竖排 变 横排 ctrl + f 使用正则表达式 \r\n 替换换行符 使用:sql语句中的 过滤条件 in中,往往适合范围查找 ...
- Office2016只安装三件套方法
转载 Office2016只安装三件套方法(word,ppt,excel) 2019-03-01 23:30:03 Kellen5l 阅读数 11618更多 分类专栏: Office 版权声明:本 ...
- 数据类中引用virtual
public class City { [Key] public int CityID { set; get; } [Display(Name = "城市名称")] [Requir ...
- java_序列化
import java.io.*; class People implements Serializable { /* * 序列化和反序列化的时候,会抛出就NotSerializableExcepti ...
- 数组,List,Set相互转化
1.数组转化为List: String[] strArray= new String[]{"Tom", "Bob", "Jane"}; Li ...
- Android开发 Tablayout的学习
前言 Tablayout一般做主页底下的导航栏开发或者上面的选择栏开发,就个人感觉Tablayout用于主页导航栏会比BottomNavigationView更好,自定义方面也更容易.缺点是没有动画也 ...