#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 51111;
// i64 gcd(i64 a,i64 b){return b?gcd(b,a%b):a;}
i64 gcd(i64 _a, i64 _b)
{
if (!_a || !_b)
{
return max(_a, _b);
}
i64 _t;
while ((_t = _a % _b))
{
_a = _b;
_b = _t;
}
return _b;
}
i64 ext_gcd (i64 _a, i64 _b, i64 &_x, i64 &_y)
{
if (!_b)
{
_x = 1;
_y = 0;
return _a;
}
i64 _d = ext_gcd (_b, _a % _b, _x, _y);
i64 _t = _x;
_x = _y;
_y = _t - _a / _b * _y;
return _d;
}
i64 invmod (i64 _a, i64 _p)
{
i64 _ans, _y;
ext_gcd (_a, _p, _ans, _y);
_ans < 0 ? _ans += _p : 0;
return _ans;
}
vector<i64>p;
bool isp(i64 x)
{
for(int i=0;p[i]*p[i]<=x;i++)
{
if(x%p[i]==0)
{
return false;
}
}
return true;
}
void init()
{
p.clear();
p.pb(2);
for(int i=3;i<211111;i++)
{
if(isp(i))
{
p.pb(i);
}
}
return ;
}
i64 s[maxn];
i64 s2[maxn];
i64 n,m,xx;
i64 ans;
void gao(int x)
{
int temp;
MM(s,0);
for(int i=0;p[i]<=x;i++)
{
temp = x;
while(temp>=p[i])
{
temp/=p[i];
s[i]+=temp;
}
}
return ;
}
i64 mod(i64 a,i64 x,i64 p)
{
i64 re = 1;
a = a%p;
while(x)
{
if(x&1)
{
re*=a;
re%=p;
}
x>>=1;
a=a*a%p;
}
return re;
}
int main()
{
init();
int T;
cin>>T;
for(int tt=1;tt<=T;tt++)
{
cin>>n>>m>>xx;
n = n + m -2;
m -= 1;
ans = 1;
ans %= xx;
gao(n);
for(int i=0;i<maxn;i++)
{
s2[i]=s[i];
}
gao(n-m);
for(int i=0;i<maxn;i++)
{
s2[i]-=s[i];
}
gao(m);
for(int i=0;i<maxn;i++)
{
s2[i]-=s[i];
}
for(int i=0;i<maxn;i++)
{
if(s2[i])
{
ans*=mod(p[i],s2[i],xx);
ans%=xx;
}
}
cout<<ans<<endl;
}
return 0;
}
分享到:
相关推荐
visiting_the_doctor046
六年级上册英语表格式导学案-unit 8 visiting museums 沪教牛津版(深圳用).doc
小学六年级下册英语第一单元《visiting Canada》课件.PPTX
英语六年级上册unit_8《visiting_museums》教案页.pdf
六年级下册英语教案-Unit 1 Visiting Canada Lesson 1 人教新起点版.docx
六年级下册英语教案-Unit 1 Visiting Canada Lesson 3 人教新起点版.docx
六年级下册英语教案-Unit 1 Visiting Canada Lesson 2 人教新起点版.docx
六年级下册英语学案 -Unit 1 Visiting Canada Lesson 2 人教(新起点).docx
六年级上册英语课件-Unit 8 Visiting museums 牛津上海版 (三起) (共45张PPT).ppt
英语写作如今,似乎是一个激烈辩论的技术发展,是否会导致很多传统文化的丧失。至于我个人来说,传统的文化可能会在将来取代了高科技。
Kangas visiting from the University of Tampere and Paul Coughlan visiting from the Univer sity of Dublin Trinity College I want to thank the translation team for their effort ">These lecture notes ...
雅思写作经典范文 pdf格式非常适合模仿 经典写作题目
人教版新起点六年级英语下册Unit1VisitingCanadaLesson1学案.pdf
该项目是通过引导的。 您将在下面找到一些有关如何执行常见任务的信息。 您可以在找到本指南的最新版本。 目录 自动格式化代码 更改页面<title> 安装依赖项 导入组件 代码分割 添加样式表 ...met
人教新起点六年级下册英语人教版六下UnitUnit1VisitingCanada第三课时试题.pdf
He was a visiting professor at Washington University in St. Louis in 1994-95. His research interests lie in the areas of the theory of interpolation of operators, weighted inequalities, and most ...
site by visiting it thousands times within seconds. Some technique such as multithread, socket, HTTP are used in WebClick. If you have any advice,please write to me. Good day! Rushing...
Software patterns have significantly changed the way we design…’ is how POSA5 starts out—its preface, its self-explanation, maybe its ...where the entrance is obvious is not worth visiting.
(1) A good tester relentlessly strives for perfection. (2) Visiting all the stat
(1) A good tester relentlessly strives for perfection. (2) Visiting all the stat