zoukankan      html  css  js  c++  java
  • 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=1;
        while(y){
            if(y&1)res=res*x%MOD;
            y>>=1;
            x=x*x%MOD;
        }
        return res;
    }
    int main(){
        int i,j,group,Case=0;
        while(cin>>n){
            long long temp=ksm(2,MOD-2);
            n=(ksm(3,n+1)-1+MOD)%MOD;
            cout<<(n*temp)%MOD<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Python day43 :pymysql模块/查询,插入,删除操作/SQL注入完全问题/事务/模拟登录注册服务器/视图/函数/存储过程
    docker
    Linux 05
    Linux04
    Linux 03
    Linux 02
    go语言
    go语言
    go语言
    Linux
  • 原文地址:https://www.cnblogs.com/Kurokey/p/5584037.html
Copyright © 2011-2022 走看看