hdu-4990 Reading comprehension(快速幂+乘法逆元)
题目链接:
Reading comprehension
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include<iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include<vector>
const int MAX=100000*2;
const int INF=1e9;
int main()
{
int n,m,ans,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
ans=0;
for(i=1;i<=n;i++)
{
if(i&1)ans=(ans*2+1)%m;
else ans=ans*2%m;
}
printf("%d\n",ans);
}
return 0;
}
[Technical Specification]
1<=n, m <= 1000000000
/*Accepted 4990 0MS 1568K 518 B G++ 2014300227*/
#include <bits/stdc++.h>
using namespace std;
const int N=3e5+;
typedef long long ll;
int n,m;
ll fastpow(int x,int y)
{
int temp=x;
ll mod=*(ll)y;
ll ans=,base=;
while(x)
{
if(x&)ans=(ans*base%mod);
base=base*base%mod;
x=(x>>);
}
if(temp%==)return (ans-%mod+mod)%mod;
else return (ans-%mod+mod)%mod;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
printf("%lld\n",fastpow(n+,m)/);
} return ;
}
hdu-4990 Reading comprehension(快速幂+乘法逆元)的更多相关文章
- HDU - 4990 Reading comprehension 【矩阵快速幂】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4990 题意 初始的ans = 0 给出 n, m for i in 1 -> n 如果 i 为奇 ...
- Reading comprehension HDU - 4990 (矩阵快速幂 or 快速幂+等比数列)
;i<=n;i++) { )ans=(ans*+)%m; %m; } 给定n,m.让你用O(log(n))以下时间算出ans. 打表,推出 ans[i] = 2^(i-1) + f[i-2] 故 ...
- HDU 4990 Reading comprehension 简单矩阵快速幂
Problem Description Read the program below carefully then answer the question.#pragma comment(linker ...
- 51Nod 1013 3的幂的和 快速幂 | 乘法逆元 | 递归求和公式
1.乘法逆元 直接使用等比数列求和公式,注意使用乘法逆元 ---严谨,失细节毁所有 #include "bits/stdc++.h" using namespace std; #d ...
- HDU 4990 Reading comprehension
快速幂 #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #i ...
- hdu 4990 Reading comprehension 二分 + 快速幂
Description Read the program below carefully then answer the question. #pragma comment(linker, " ...
- HDU 4990 Reading comprehension(矩阵快速幂)题解
思路: 如图找到推导公式,然后一通乱搞就好了 要开long long,否则红橙作伴 代码: #include<set> #include<cstring> #include&l ...
- HDU 4990 Reading comprehension 矩阵快速幂
题意: 给出一个序列, \(f_n=\left\{\begin{matrix} 2f_{n-1}+1, n \, mod \, 2=1\\ 2f_{n-1}, n \, mod \, 2=0 \end ...
- HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
随机推荐
- http://blog.csdn.net/zh521zh/article/details/52687922
http://blog.csdn.net/zh521zh/article/details/52687922
- 使用和不使用navigationbar分别处理显示和返回页面
不使用navigationbar的情况下 AnnounceViewController *pushView = [[AnnounceViewController alloc]init];pushVie ...
- js转换金额为中文大写
function changeMoneyToChinese(money){ var cnNums = new Array("零","壹","贰&quo ...
- 【spring cloud】Feign使用填坑
引用地址:https://blog.csdn.net/liuchuanhong1/article/details/54728681 问题一: 在前面的示例中,我们讲过 @RequestMapping( ...
- Android 关于view的getLayoutParams().width,getWidth(),getMeasuredWidth();
习惯了使用xml的布局方式,当动态布局的时候就有许多疑点,记录一下,帮助我这老头一样的记忆力. 网上也有许多解析这getLayoutParams().width,getWidth(),getMeasu ...
- 调用tensorflow中的concat方法时Expected int32, got list containing Tensors of type '_Message' instead.
grid = tf.concat(0, [x_t_flat, y_t_flat, ones])#报错语句 grid = tf.concat( [x_t_flat, y_t_flat, ones],0) ...
- mac 当前位置打开终端
做开发时经常会遇到在当前目录打开终端的情况,一直都是先启动终端,然后再切换到当前目录,今天发现了一个新的方法,虽然不是一步到位,但比以前快多了. 工具/原料 mac系统 苹果电脑 方法/步骤 ...
- Rebuild account Windows 10 in Domain
cmd ‘administrator’Regedit 1. Check User Profiles HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\C ...
- AngularJS的ng-repeat显示属性名和属性值
代码下载:https://files.cnblogs.com/files/xiandedanteng/AngularJSAuthorRepeat.rar 代码: <!DOCTYPE HTML P ...
- Oracle对没有主键的表分页
普通情况对于有主键,能够做唯一表识的表.我们能够利用主键和rownum配合实现.比如: select scott.emp.* from scott.emp left join (select empn ...