HDU 5187
超简单的公式题(2^n-2)。不过,要过可不容易,因为会爆64位,所以,可以使用快速乘法。
#include <iostream>
#include <cstdio>
#include <algorithm>
#define LL unsigned __int64
using namespace std; LL n,p; LL mul(LL x,LL m,LL p)///????
{
LL re=;
while(m){
if(m&){
re=(re+x)%p;
}
x=(x+x)%p;
m>>=;
}
return re;
} LL quick(LL n,LL p){
LL ret=1ll,t=;
while(n){
if(n&) ret=mul(ret,t,p);
n>>=;
t=mul(t,t,p);
}
return ret;
} int main(){
while(scanf("%I64d%I64d",&n,&p)!=EOF){
if(n==1ll){
if(p>)puts("");
else puts("");
continue;
}
LL ans=quick(n,p);
printf("%I64d\n",((ans-)%p+p)%p);
}
return ;
}
HDU 5187的更多相关文章
- hdu 5187 高速幂高速乘法
http://acm.hdu.edu.cn/showproblem.php?pid=5187 Problem Description As one of the most powerful brush ...
- HDU 5187 zhx's contest 快速幂,快速加
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5187 bc(中文): http://bestcoder.hdu.edu.cn/contes ...
- hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]
传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 5187 zhx's contest
题目分析如果n=1,答案是1,否则答案是2n−2. 证明:ai肯定是最小的或者最大的.考虑另外的数,如果它们的位置定了的话,那么整个序列是唯一的. 那么ai是最小或者最大分别有2n−1种情况,而整个序 ...
- HDU - 5187 - zhx's contest (高速幂+高速乘)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- hdu 5187 快速幂 + 快速乘 值得学习
就是以那个ai为分水岭,左边和右边都分别是单调增或单调减如图 就这四种情况,其中头两种总共就是两个序列,也就是从头到尾递增和从头到尾递减. 后两种方式就是把序列中德数分 ...
- hdu 5187(高精度快速幂)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 5187 zhx's contest(防爆__int64 )
Problem Description As one of the most powerful brushes, zhx is required to give his juniors n probl ...
- hdu 5187 zhx's contest (快速幂+快速乘)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
随机推荐
- 【POJ 1456】 Supermarket
[题目链接] http://poj.org/problem?id=1456 [算法] 贪心 + 堆 [代码] #include <algorithm> #include <bitse ...
- 444D
分类 首先我们要对询问分类,如果相差log级别就第一种询问,否则第二种. 第一种直接暴力lower_bound,复杂度玄学 第二种归并,复杂度玄学 但是就是过了.感觉很容易卡. #include< ...
- AMQP server localhost:5672 closed the connection. Check login credentials: Socket closed
2016-04-13 09:23:38.755 18850 INFO oslo.messaging._drivers.impl_rabbit [req-fafc8542-9403-4b5a-89d2- ...
- com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1问题出现的原因及解决办法
转自:https://blog.csdn.net/shinchan_/article/details/37818927 com/opensymphony/xwork2/spring/SpringObj ...
- 想要学好C/C++,我到底要看多少书才能成为一个合格的C/C++工程师?
如何学好C语言 这可能是很多朋友的问题,我以前也有这样的感觉,编程编到一定的时候,发现能力到了瓶颈,既不深,也不扎实,半吊子.比如:你长期地使用Java和.NET ,这些有虚拟机的语言对于开发便利是便 ...
- [转]利用 NPOI 變更字體尺寸及樣式
本文转自:http://blog.cscworm.net/?p=1650 利用 NPOI 變更字體尺寸及樣式: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
- PHP 二维数组排序 可以按指定 键值排序
<?php header("Content-Type:utf-8"); $arr = array( 0 => array( 'name' => '国际原油价格', ...
- A - Supermarket
Problem description We often go to supermarkets to buy some fruits or vegetables, and on the tag the ...
- background使用
background-position 有两个参数,定义背景图片起始位置可选值有: center top left right bottom px % background-size 可以用 px % ...
- python--5、包
包 包,即一个包含__init__.py文件的文件夹,创建包的目的也就是为了用文件夹将文件(模块)组织起来.python3中,即使包里没有__init__.py文件,仍能import使用.而pytho ...