This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define oo 1e9
const int MAX = 203, MOD = 1e9 + 7;
int n;
int vis[MAX];
int Hcnt[MAX];
int pw[MAX];
int binpow(int a, int b){
if(b == 0) return 1;
if(b & 1) return binpow(a, b - 1) % MOD * a % MOD;
else return binpow(a * a % MOD, b / 2) % MOD;
}
int inv(int a){
return binpow(a, MOD - 2);
}
void dfs(int node, int h){
if(vis[node] || node > n || node < 1) return;
vis[node] = 1;
Hcnt[h]++;
dfs(node * 2, h + 1);
dfs(node * 2 + 1, h + 1);
dfs(node / 2, h + 1);
}
void solve(){
cin >> n;
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= n; j++){
vis[j] = 0;
Hcnt[j] = 0;
}
dfs(i, 0);
int oth = n;
for(int j = 0; j <= n; j++){
if(!Hcnt[j]) break;
oth -= Hcnt[j];
ans = (ans + j * (pw[Hcnt[j]] - 1) % MOD * pw[oth] % MOD) % MOD;
}
}
cout << ans * inv(pw[n] - 1) % MOD << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t; cin >> t;
pw[0] = 1;
for(int i = 1; i < MAX; i++){
pw[i] = pw[i - 1] * 2 % MOD;
}
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |