codeforces-1594e1

https://codeforces.com/problemset/problem/1594/E1

一道很简单的题,但是模运算的时候出错了,想当然的把 4 N 4^ N 4N中的 N N N取模了。在此记录一下:
在这里插入图片描述

#include<bits/stdc++.h>

using namespace std;
//    clock_t start, end;
//    start = clock();
//    end = clock();
//    cout << (double) (end - start) / CLOCKS_PER_SEC << endl;
//ios::sync_with_stdio(false);
#define  int long long
#define rep(i, x, y) for(int i=(x);i<=(y);++i)
#define dep(i, x, y) for(int i=(x);i>=(y);--i)
#define gcd(a, b) __gcd(a,b)
const long long mod = 1e9+7;
const int maxn = 1e6 + 10;

int lowbit(int x) { return x & -x; }

bool ispow(int n) { return (n & (n - 1)) == 0; }//O(1) 判断是否是 2^k(2的k次方)

int fast(int a, int n) {
    int base = a, res = 1;
    while (n) {
        if (n & 1)res = ((res % mod) * (base % mod)) % mod;
        base = ((base % mod) * (base % mod)) % mod;
        n >>= 1;
    }
    return res%mod;
}


//937481864
signed main() {

    int k;
    cin>>k;
    int q=((int)1<<k)-2;
    int ans=fast(4,q);
    ans*=6;
    cout<<ans%mod<<endl;

    return 0;
}

费马小定理的优化(其实在这里不会快多少—_—|||):

    #include<bits/stdc++.h>
     
    using namespace std;
    //    clock_t start, end;
    //    start = clock();
    //    end = clock();
    //    cout << (double) (end - start) / CLOCKS_PER_SEC << endl;
    //ios::sync_with_stdio(false);
    #define  int long long
    #define rep(i, x, y) for(int i=(x);i<=(y);++i)
    #define dep(i, x, y) for(int i=(x);i>=(y);--i)
    #define gcd(a, b) __gcd(a,b)
    const long long mod = 1e9 + 7;
    const int maxn = 1e6 + 10;
     
    int lowbit(int x) { return x & -x; }
     
    bool ispow(int n) { return (n & (n - 1)) == 0; }//O(1) 判断是否是 2^k(2的k次方)
     
    int fast(int a, int n) {
        int base = a, res = 1;
        while (n) {
            if (n & 1)res = ((res % mod) * (base % mod)) % mod;
            base = ((base % mod) * (base % mod)) % mod;
            n >>= 1;
        }
        return res;
    }
     
    char s[maxn];
    int dp[1000000][10];
    int las[maxn];
    char txt[] = "nuhe";
     
    signed main() {
     
        int k;
        cin >> k;
        int z = ((int)1<<k) - 2;
        z = z %(mod -  1);
        cout << (6 % mod) * (fast(4, z) % mod) % mod << endl;
        return 0;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值