BZOJ 1951 [SDOI2010]古代猪文 (组合数学+欧拉降幂+中国剩余定理)
题目大意:求$G^{\sum_{m|n} C_{n}^{m}}\;mod\;999911659\;$的值$(n,g<=10^{9})$
并没有想到欧拉定理..
999911659是一个质数,所以$\varphi(p)=p-1$
利用欧拉定理,降幂化简式子$G^{\sum_{m|n} C_{n}^{m}\;mod\;\varphi(p)}$
这样,指数部分可以用$Lucas$+中国剩余定理求解
然而..$G>10^9$很大,可能和模数$999911659$不互质!所以质数要额外加上$\varphi(p)$
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 10100
#define ull unsigned long long
#define ll long long
#define maxn 36000
using namespace std; ll n,g;
const ll m[]={,,,}; ll qpow(ll x,ll y,const ll &mod){
ll ans=;
while(y){
if(y&) ans=(ans*x)%mod;
x=(x*x)%mod,y>>=;
}return ans;
}
namespace excrt{
ll exgcd(ll a,ll b,ll &x,ll &y){
if(!b) {x=,y=;return a;}
ll ans=exgcd(b,a%b,x,y);
ll t=x;x=y,y=t-a/b*y;
return ans;
}
ll qadd(ll x,ll y,const ll &mod){
ll ans=;
while(y){
if(y&) ans=(ans+x)%mod;
x=(x+x)%mod,y>>=;
}return ans;
}
ll ans=,M=;
void insert(ll A,ll B)
{
ll a=A,b=B,c=(a-ans%b+b)%b,x,y,g;
g=exgcd(M,b,x,y);b/=g;
//if(c/g!=0) return;
//x=qadd(x,c/g,b);
x=x*(c/g)%b;
ans+=x*M,M*=b,ans=(ans%M+M)%M;
}
};
int son[N],d[N],ps[N],num,cnt;
namespace calc{
ll mul[maxn+],inv[maxn+],minv[maxn+];
void Pre(const ll &mo)
{
mul[]=mul[]=inv[]=inv[]=minv[]=minv[]=;
for(int i=;i<mo;i++){
mul[i]=mul[i-]*i%mo;
inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
minv[i]=minv[i-]*inv[i]%mo;
}
}
ll C(ll a,ll b,const ll &mo)
{return mul[a]*minv[b]%mo*minv[a-b]%mo;}
ll Lucas(ll a,ll b,const ll &mo)
{
if(b>a) return ;
if(a<mo&&b<mo) return C(a,b,mo);
return Lucas(a/mo,b/mo,mo)*Lucas(a%mo,b%mo,mo)%mo;
}
ll solve(const ll &mo)
{
for(int i=;i<mo;i++)
mul[i]=inv[i]=minv[i]=;
Pre(mo);ll ans=;
for(int i=;i<=cnt;i++)
(ans+=Lucas(n,son[i],mo))%=mo;
return ans;
}
};
void dfs_son(int i,ll s)
{
if(i>num) {son[++cnt]=s;return;}
for(int j=;j<=d[i];j++)
dfs_son(i+,s),s*=ps[i];
}
void get_son(ll a)
{
int sq=sqrt(a);
for(int i=;i<=sq;i++)
if(a%i==){
ps[++num]=i;
while(a%i==)
d[num]++,a/=i;
}
if(a!=)
ps[++num]=a,d[num]++;
dfs_son(,);
}
const ll smod=; int main()
{
scanf("%lld%lld",&n,&g);
get_son(n);
for(int i=;i<;i++)
{
ll ans=calc::solve(m[i]);
excrt::insert(ans,m[i]);
}
ll pw=excrt::ans;
ll ans=qpow(g,pw+smod-,smod);
printf("%lld\n",ans);
return ;
}
BZOJ 1951 [SDOI2010]古代猪文 (组合数学+欧拉降幂+中国剩余定理)的更多相关文章
- BZOJ 1951: [Sdoi2010]古代猪文( 数论 )
显然答案是G^∑C(d,N)(d|N).O(N^0.5)枚举N的约数.取模的数999911659是质数, 考虑欧拉定理a^phi(p)=1(mod p)(a与p互质), 那么a^t mod p = a ...
- BZOJ 1951: [Sdoi2010]古代猪文 [Lucas定理 中国剩余定理]
1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2194 Solved: 919[Submit][Status] ...
- [SDOI2010]古代猪文 (欧拉,卢卡斯,中国剩余)
[SDOI2010]古代猪文 \(solution:\) 这道题感觉综合性极强,用到了许多数论中的知识: 质因子,约数,组合数 欧拉定理 卢卡斯定理 中国剩余定理 首先我们读题,发现题目需要我们枚举k ...
- 【刷题】BZOJ 1951 [Sdoi2010]古代猪文
Description "在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心--" --选自猪王国民歌 很久 ...
- bzoj 1951 [Sdoi2010]古代猪文(数论知识)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1951 [思路] 一道优(e)秀(xin)的数论题. 首先我们要求的是(G^sigma{ ...
- bzoj 1951 [Sdoi2010]古代猪文 ——数学综合
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1951 数学综合题. 费马小定理得指数可以%999911658,又发现这个数可以质因数分解.所 ...
- bzoj 1951: [Sdoi2010]古代猪文 【中国剩余定理+欧拉定理+组合数学+卢卡斯定理】
首先化简,题目要求的是 \[ G^{\sum_{i|n}C_{n}^{i}}\%p \] 对于乘方形式快速幂就行了,因为p是质数,所以可以用欧拉定理 \[ G^{\sum_{i|n}C_{n}^{i} ...
- bzoj 1951: [Sdoi2010]古代猪文
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...
- BZOJ.1951.[SDOI2010]古代猪文(费马小定理 Lucas CRT)
题目链接 \(Description\) 给定N,G,求\[G^{\sum_{k|N}C_n^k}\mod\ 999911659\] \(Solution\) 由费马小定理,可以先对次数化简,即求\( ...
随机推荐
- STL中的迭代器的使用
package com.text; import java.lang.reflect.Field;import java.util.ArrayList;import java.util.Iterato ...
- what is udev?
如果你使用Linux比较长时间了,那你就知道,在对待设备文件这块,Linux改变了几次策略.在Linux早期,设备文件仅仅是是一些带有适当的属性集的普通文件,它由mknod命令创建,文件存放在/dev ...
- C语言基本语法——数组
一.一维数组 1.什么是数组 2.数组语法 3.下标 4.初始化 5.数组名和数组首地址 二.一维数组的应用 1.数组的赋值与拷贝 2.数组的正反遍历 3.随机数 4.数组乱序 5.数组的重复 三.二 ...
- JavaScript 运行机制 & EventLoop
JavaScript 运行机制 & EventLoop 看阮老师博客和自己的理解,记录的学习笔记,js的单线程和 事件EventLoop 机制. 1. JavaScript是单线程 JavaS ...
- PHP中的 Iterator 与 Generator
在讲解生成器之前先介绍一下迭代器: 在 PHP 中,通常情况下遍历数组使用 foreach 来遍历. 如果我们要想让一个对象可以遍历呢? PHP 为我们提供了 Iterator 接口,只要实现了这个接 ...
- dubbo Failed to check the status of the service com.user.service.UserService. No provider available for the service
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'u ...
- Nutch命令大全
Nutch采用了一种命令的方式进行工作,其命令可以是对局域网方式的单一命令也可以是对整个Web进行爬取的分步命令.主要的命令如下: 1. Crawl Crawl是"org.apache.nu ...
- Intellij idea 自动完成的变量名称首字母变为小写
Intellij idea 自动完成的变量名称首字母变为小写 好像没有什么好的自动办法,自己输入一个小写的字母吧,然后Idea会出提示.
- NYOJ 915 +-字符串【贪心】
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描写叙述 Shiva得到了两个仅仅有加号和减号的字符串,字串长度同样.Shiva一次能够把一个加号和它相邻的减号交换 ...
- fastjson 的简单使用
public static void main(String[] args) { /*普通对象与json相互转换*/ User u = new User("miquan", &qu ...