题目链接:传送门

题目大意:求(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的幂的和)的更多相关文章

  1. 51nod 1013 3的幂的和 - 快速幂&除法取模

    题目地址:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 Konwledge Point: 快速幂:https:/ ...

  2. 快速幂取模模板 && 51nod 1013 3的幂的和

    #include <iostream> #include <cstdio> #include <cmath> #include <vector> #in ...

  3. 51Nod 1013 3的幂的和 快速幂 | 乘法逆元 | 递归求和公式

    1.乘法逆元 直接使用等比数列求和公式,注意使用乘法逆元 ---严谨,失细节毁所有 #include "bits/stdc++.h" using namespace std; #d ...

  4. 51nod 1013【快速幂+逆元】

    等比式子: Sn=(a1-an*q)/(1-q) n很大,搞一发快速幂,除法不适用于取膜,逆元一下(利用费马小定理) 假如p是质数,且gcd(a,p)=1,那么 a^(p-1)≡1(mod p).刚好 ...

  5. 51Nod 1013 3的幂的和(快速幂+逆元)

    #include <iostream> #include <algorithm> #include <string> #define MOD 1000000007 ...

  6. 51nod 1013:3的幂的和 快速幂

    1013 3的幂的和 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 求:3^0 + 3^1 +...+ 3^(N) mod 1000000007 ...

  7. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

  8. 51nod 1013快速幂 + 费马小定理

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 这是一个等比数列,所以先用求和公式,然后和3^(n+1)有关,有n ...

  9. AC日记——3的幂的和 51nod 1013

    3的幂的和 思路: 矩阵快速幂:   sn-1      3 1        sn   *          = 1     0 1  1 来,上代码: #include <cstdio> ...

随机推荐

  1. cookie技术自动登录

    user public class User implements Serializable{ private String username; private String nick; privat ...

  2. kettle--组件(3)--行转列

    组件图如下: 以上操作可以这么理解: IF(DATA1=DATA4) THEN DATA2=DATA3 也就是关键字值的数值会与关键字段的数值匹配,匹配上了就显示数据value filedname所填 ...

  3. sql替换字符串部分内容

    update 表名 set 字段名=replace(cast(与前面一样的字段名 as varchar(8000)) ,'原本内容','想要替换成什么') update News set news_d ...

  4. Spring学习笔记(四)-- Spring事务全面分析

    通过本系列的文章对Spring的介绍,我们对Spring的使用和两个核心功能IOC.AOP已经有了初步的了解,结合我个人工作的情况,因为项目是金融系 统.那对事务的控制是不可缺少的.而且是很严格的控制 ...

  5. linux下/etc/hosts 和hostname文件的区别

    很过人一提到更改hostname首先就想到修改/etc/hosts文件,认为hostname的配置文件就是/etc/hosts.其实不是的. hosts文件的作用相当如DNS,提供IP地址到hostn ...

  6. 第一个EJB示例

    FirstEJB2.0.zip Eclipse + JBoss 5.1 Ejb3Example.zip Eclipse + JBoss 7.1 注意点: 1. jboss 增加用户: D:\DevPr ...

  7. 浅谈iOS 5的StoryBoard

    转自:http://blog.163.com/wangy_0223/blog/static/450146612012318113233218/ 示例代码的Github地址:https://github ...

  8. [个人开发人员赚钱九]做一个日收入10元的APP!

    [导语]尽管讲了非常多个人开发人员的文章.但新手开发人员怎样赚自己的第一个10块钱.确是最难的事情.群里有人说都不知道干什么app赚钱.全然没有想法.而且常常问我有什么高速赚钱的方法.我仅仅能遗憾地 ...

  9. Python学习之warn()函数

    warn()函数位于warnings模块中,用来发出警告,或者忽略它或引发异常. def warn(message, category=None, stacklevel=, source=None) ...

  10. DOCTYPE 与浏览器模式分析

    DOCTYPE 的诞生 DOCTYPE,或者称为 Document Type Declaration(文档类型声明,缩写 DTD).通常情况下,DOCTYPE 位于一个 HTML 文档的最前面的位置, ...