ans=2^(n-1)%mod = 2^((n-1)%(mod-1)+(n-1)/(mod-1)*(mod-1))%mod=2^((n-1)%(mod-1))%mod*2^((n-1)/(mod-1)*(mod-1))%mod=2^((n-1)%(mod-1))%mod

对于(n-1)%(mod-1),可以先算出n%(mod-1),那么(n-1)%(mod-1) = (n%(mod-1)-1+(mod-1))%(mod-1)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int maxn = 2e5;
const int mod = 1e9 + 7;
string s;
int n;
long long ipow(long long a, long long x) {
long long ans = 1;
while (x) {
if (x & 1) ans = ans * a % mod;
a = a * a % mod;
x >>= 1;
}
return ans;
}
int main() {
while (cin >> s) {
long long num = 0;
for (int i = 0; i < s.size(); i++) num = (num*10+(s[i]-'0'))%(mod-1);
num = (num-1+mod-1) % (mod-1);
cout << ipow(2, num) << endl;
}
return 0;
}