51NOD 1013(3的幂的和)
题目链接:传送门
题目大意:求(3^0+3^1+3^2+3^3+...+3^n)%1e9的值
题目思路:乘法逆元裸题
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 1000010
#define maxn 400005
typedef pair<int,int> PII; long long n,m;
long long ksm(long long x,long long y){
long long res=;
while(y){
if(y&)res=res*x%MOD;
y>>=;
x=x*x%MOD;
}
return res;
}
int main(){
int i,j,group,Case=;
while(cin>>n){
long long temp=ksm(,MOD-);
n=(ksm(,n+)-+MOD)%MOD;
cout<<(n*temp)%MOD<<endl;
}
return ;
}
51NOD 1013(3的幂的和)的更多相关文章
- 51nod 1013 3的幂的和 - 快速幂&除法取模
题目地址:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 Konwledge Point: 快速幂:https:/ ...
- 快速幂取模模板 && 51nod 1013 3的幂的和
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #in ...
- 51Nod 1013 3的幂的和 快速幂 | 乘法逆元 | 递归求和公式
1.乘法逆元 直接使用等比数列求和公式,注意使用乘法逆元 ---严谨,失细节毁所有 #include "bits/stdc++.h" using namespace std; #d ...
- 51nod 1013【快速幂+逆元】
等比式子: Sn=(a1-an*q)/(1-q) n很大,搞一发快速幂,除法不适用于取膜,逆元一下(利用费马小定理) 假如p是质数,且gcd(a,p)=1,那么 a^(p-1)≡1(mod p).刚好 ...
- 51Nod 1013 3的幂的和(快速幂+逆元)
#include <iostream> #include <algorithm> #include <string> #define MOD 1000000007 ...
- 51nod 1013:3的幂的和 快速幂
1013 3的幂的和 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 求:3^0 + 3^1 +...+ 3^(N) mod 1000000007 ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
- 51nod 1013快速幂 + 费马小定理
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 这是一个等比数列,所以先用求和公式,然后和3^(n+1)有关,有n ...
- AC日记——3的幂的和 51nod 1013
3的幂的和 思路: 矩阵快速幂: sn-1 3 1 sn * = 1 0 1 1 来,上代码: #include <cstdio> ...
随机推荐
- Linux 添加开机启动项的三种方法
linux 添加开机启动项的三种方法. (1)编辑文件 /etc/rc.local 输入命令:vim /etc/rc.local 将出现类似如下的文本片段: #!/bin/sh## This scri ...
- windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决
windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决 一.发现问题 由于tomcat内存溢出,在wind ...
- thinkphp 编辑器kindeditor
首先,去官网下载最新版的kindeditor,然后把里面asp,jsp,net,example的全删除,然后改名为editor放进public(最外层目录的public)文件夹里面 在目录lib目录建 ...
- 用Fiddler 发送post请求
在调试web api的时候,若是get 请求,可以直接在浏览器里查看结果,如果是put,或者post请求在浏览器地址栏里就没有办法了. 下面介绍一下,如何利用fiddler模拟post请求. 也可以用 ...
- C# JSON格式数据高级用法
JSON简介 JSON(全称为JavaScript ObjectNotation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集.JSON采用完全独立于语言的文本格式, ...
- python --存储对象
转自:http://www.cnblogs.com/vamei/archive/2012/09/15/2684781.html 在之前对Python对象的介绍中 (面向对象的基本概念,面向对象的进一步 ...
- 开始使用Bootstrap
bootstrap使用到的图标字体文件格式有 .woff,IIS7下需要添加MIME映射:.woff application/x-font-woff
- sklearn 随机森林方法
Notes The default values for the parameters controlling the size of the trees (e.g. max_depth, min_s ...
- 点滴积累【C#】---操作文件
操作文件 写入文件效果: 写入文件代码: private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) { try { File ...
- void *指针的加减运算
1.手工写了一个程序验证void *指针加减运算移动几个字节: //本程序验证空类型指针减1移动几个字节 #include <stdio.h> int main(int argc, cha ...