博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zhx's contest (hdu 5187 快速幂+快速乘法)
阅读量:7239 次
发布时间:2019-06-29

本文共 2822 字,大约阅读时间需要 9 分钟。

zhx's contest

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 352    Accepted Submission(s): 120

Problem Description
As one of the most powerful brushes, zhx is required to give his juniors 
n problems.
zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a beautiful way.
zhx defines a sequence {
ai}
 beautiful if there is an i that matches two rules below:
1: a1..ai are monotone decreasing or monotone increasing.
2: ai..an are monotone decreasing or monotone increasing.
He wants you to tell him that how many permutations of problems are there if the sequence of the problems' difficulty is beautiful.
zhx knows that the answer may be very huge, and you only need to tell him the answer module p.
 

 

Input
Multiply test cases(less than 
1000). Seek EOF as the end of the file.
For each case, there are two integers n and p separated by a space in a line. (1n,p1018)
 

 

Output
For each test case, output a single line indicating the answer.
 

 

Sample Input
2 233 3 5
 

 

Sample Output
2 1
Hint
In the first case, both sequence {1, 2} and {2, 1} are legal. In the second case, sequence {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1} are legal, so the answer is 6 mod 5 = 1
 

 

Source
 

 

Recommend
hujie   |   We have carefully selected several similar problems for you:            
 

 

题意:数字1~n,按某种顺序排列,且满足下列某一个条件:(1)a1~ai递增,ai~an递减(2)a1~ai递减,ai~an递增。问有多少种不同的排列。

思路:首先是全部递减或全部递增各一种;另外就是满足上列两个条件的情况了,要想满足条件(1)那就只能把最大的n放在i位置,共有C(1,n-1)+C(2,n-1)+。。。+C(n-2,n-1)即2^(n-1)-2;条件(2)与(1)相同,所以共有(2^(n-1)-2)*2+2=2^n-2.

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1005#define MAXN 2005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6#define lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE(i,a,b) for(i = a; i <= b; i++)#define FRL(i,a,b) for(i = a; i < b; i++)#define mem(t, v) memset ((t) , v, sizeof(t))#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define DBG pf("Hi\n")typedef __int64 ll;using namespace std;ll n,p;ll quickmul(ll x,ll m) //快速乘法,与快速幂相似{ ll re=0; while(m){ if(m&1){ re=(re+x)%p; } x=(x+x)%p; m>>=1; } return re;}ll pow_m(ll a,ll n) //快速幂{ ll ret=1; ll temp=a%p; while (n){ if (n&1) ret=quickmul(ret,temp)%p; temp=quickmul(temp,temp)%p; n>>=1; } return ret;}int main(){ int i,j; while (~scanf("%I64d%I64d",&n,&p)) { if (n==1) //特判 { if (p==1) pf("0\n"); else pf("1\n"); continue; } pf("%I64d\n",(pow_m(2,n)-2+p)%p); } return 0;}

  

 

转载于:https://www.cnblogs.com/i8888/p/4338566.html

你可能感兴趣的文章
第十三章 接口
查看>>
进度条9
查看>>
robotframework自动化测试之测试数据
查看>>
[NOI2008]志愿者招募
查看>>
同一个闭区间上有界变差函数的和与积都是有界变差函数
查看>>
Elementary Methods in Number Theory Exercise 1.5.10
查看>>
「陶哲軒實分析」 習題 3.5.1
查看>>
大聊Python----协程
查看>>
nginx.pid-nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or direc
查看>>
在CentOS上配置SAMBA共享目录(转载)
查看>>
Linux之samba搭建
查看>>
第十三周学习笔记
查看>>
ZOJ 2770 Burn the Linked Camp 差分约束 (转)
查看>>
Python随笔1
查看>>
Ubuntu16.04搭建Postfix作为SMTP服务器
查看>>
Linux——网络端口的状态netstat、ifconfig
查看>>
android 单位总结
查看>>
canvas元素简易教程(5)(大部分转自火狐,自己只写了简单的代码分析)
查看>>
ArcCore重构-生成%_offset.h文件
查看>>
关于kafka的新的group无法订阅到topic中历史消息的问题
查看>>