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;
}