#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define ld long double
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define int long long
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e7+10 + 10, inf = 1e9+10 , mod = 1e9 + 7 ;
int a2[maxn] , dp[70][70][130] , pr[140] ;
int po2(int b){
if(b==0)return 1 ;
if(b < maxn)return a2[b];
int v =po2(b/2);
v=v *v % mod ;
if(b&1) v= v*2% mod;
return v;
}
int po(int a,int b){
if(b==0)return 1 ;
int v =po(a,b/2);
v=v *v % mod ;
if(b&1) v= v*a % mod;
return v;
}
int ch(int x ,int d , int k){
if(d==-1)return 0;
d = min(d , k-x);
return ((1ll<<(d+1))-1);
}
int ans =0 , N , d[140] ;
vector <int> cal(int p){
int x = p , k= 0 ;
vector <int> h;
while(x*2 <= N){
x *= 2 ;
k++;
}
rep(i , 0 , k)h.pb((1ll<<i)) ;
if((x+(1ll<<k)-1) <= N){
return h ;
}
int az = (x+(1ll<<k)-1) - N ;
h.back()-=az;
return h ;
}
void f(int p = 1){
if(p > N)return ;
int x= p , k =0 ;
while(x*2 <= N){
k++;
x*=2 ;
}
if((x+(1ll<<k)-1) <= N){
pr[0] = 0 ;
rep(i , 1 ,130)pr[i] = pr[i-1] + d[i] ;
rep(i , 0 , k){
int sm = 0 ;
rep(j , 0 , 120){
int t = dp[k][i][j] + (j >= i ? pr[j-i] : 0);
if(t == N)break ;
sm = (sm + po2((N-t)%(mod-1))-1);
if(sm > mod)sm -= mod ;
}
sm += mod;
if(sm > mod)sm-=mod;
ans = (ans + sm*po2(i))%mod ;
}
return ;
}
vector <int> A = cal(p*2) ;
vector <int> B = cal(p*2+1) ;
int d2[140] , ls[140] ;
rep(i , 0 , 130){
d2[i] =0 ;
ls[i] = d[i] ;
}
d2[1] = 1 ;
rep(i , 1 , 130){
d2[i] += d[i-1] ;
}
rep(i , 0 , sz(B)-1){
d2[i+2] += B[i] ;
}
rep(i , 0 , 130){
swap(d[i] , d2[i]) ;
}
f(p*2) ;
rep(i , 0 , sz(B)-1){
d[i+2] -= B[i] ;
}
rep(i , 0 ,sz(A)-1){
d[i+2] += A[i] ;
}
f(p*2+1);
rep(i , 0 , 130)d[i] = ls[i] ;
pr[0] = d[0] ;
rep(i , 1, 130)pr[i] = pr[i-1] + d[i] ;
rep(i , 1 , sz(A)-1)A[i] += A[i-1] ;
rep(i , 1, sz(B)-1)B[i] += B[i-1] ;
rep(i , 0 , 120){
if(i ==0){
ans = (ans + po2((N-1)%(mod-1))-1)%mod ;
continue ;
}
int t = pr[i] + A[min(sz(A)-1 , i-1)] + B[min(sz(B)-1 , i-1)]+1 ;
ans = (ans + po2((N-t)%(mod-1))-1)%mod ;
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
a2[0] = 1;
rep(i , 1 ,maxn-1){
a2[i] = a2[i-1]*2%mod ;
}
rep(k , 0 , 60){
rep(i , 0 , k){
rep(d , 0 , 120){
int ans = ch(i , d , k) ;
int x = i-1 , D = d-1 ;
while(x!=-1 && D!=-1){
ans++ ;
ans = (ans + ch(x+1 , D-1 , k));
D--;
x--;
}
dp[k][i][d] = ans ;
}
}
}
int T ;
cin >> T ;
while(T--){
rep(i ,0 , 120)d[i] =0 ;
int n;
cin >> n ;
N = n ;
ans =0 ;
f();
cout << ans * po(po(2,n)-1 , mod-2)%mod << "\n";
}
return 0 ;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
81420 KB |
Output is correct |
2 |
Correct |
55 ms |
81488 KB |
Output is correct |
3 |
Correct |
54 ms |
81472 KB |
Output is correct |
4 |
Correct |
57 ms |
81404 KB |
Output is correct |
5 |
Correct |
53 ms |
81492 KB |
Output is correct |
6 |
Correct |
52 ms |
81408 KB |
Output is correct |
7 |
Correct |
53 ms |
81420 KB |
Output is correct |
8 |
Correct |
55 ms |
81604 KB |
Output is correct |
9 |
Correct |
53 ms |
81372 KB |
Output is correct |
10 |
Correct |
53 ms |
81488 KB |
Output is correct |
11 |
Correct |
54 ms |
81656 KB |
Output is correct |
12 |
Correct |
53 ms |
81432 KB |
Output is correct |
13 |
Correct |
66 ms |
81804 KB |
Output is correct |
14 |
Correct |
65 ms |
81492 KB |
Output is correct |
15 |
Correct |
70 ms |
81488 KB |
Output is correct |
16 |
Correct |
66 ms |
81568 KB |
Output is correct |
17 |
Correct |
56 ms |
81488 KB |
Output is correct |
18 |
Correct |
56 ms |
81748 KB |
Output is correct |
19 |
Correct |
56 ms |
81488 KB |
Output is correct |
20 |
Correct |
56 ms |
81488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
81532 KB |
Output is correct |
2 |
Correct |
62 ms |
81492 KB |
Output is correct |
3 |
Correct |
63 ms |
81748 KB |
Output is correct |
4 |
Correct |
60 ms |
81436 KB |
Output is correct |
5 |
Correct |
62 ms |
81492 KB |
Output is correct |
6 |
Correct |
61 ms |
81500 KB |
Output is correct |
7 |
Correct |
61 ms |
81436 KB |
Output is correct |
8 |
Correct |
66 ms |
81492 KB |
Output is correct |
9 |
Correct |
62 ms |
81876 KB |
Output is correct |
10 |
Correct |
62 ms |
81476 KB |
Output is correct |
11 |
Correct |
311 ms |
81488 KB |
Output is correct |
12 |
Correct |
321 ms |
81748 KB |
Output is correct |
13 |
Correct |
309 ms |
81588 KB |
Output is correct |
14 |
Correct |
317 ms |
81752 KB |
Output is correct |
15 |
Correct |
304 ms |
81584 KB |
Output is correct |
16 |
Correct |
323 ms |
81596 KB |
Output is correct |
17 |
Correct |
309 ms |
81460 KB |
Output is correct |
18 |
Correct |
318 ms |
81420 KB |
Output is correct |
19 |
Correct |
314 ms |
81612 KB |
Output is correct |
20 |
Correct |
308 ms |
81552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
260 ms |
81720 KB |
Output is correct |
2 |
Correct |
278 ms |
81716 KB |
Output is correct |
3 |
Correct |
247 ms |
81492 KB |
Output is correct |
4 |
Correct |
248 ms |
81704 KB |
Output is correct |
5 |
Correct |
275 ms |
81492 KB |
Output is correct |
6 |
Correct |
282 ms |
81716 KB |
Output is correct |
7 |
Correct |
268 ms |
81716 KB |
Output is correct |
8 |
Correct |
273 ms |
81720 KB |
Output is correct |
9 |
Correct |
61 ms |
81468 KB |
Output is correct |
10 |
Correct |
61 ms |
81492 KB |
Output is correct |
11 |
Correct |
78 ms |
81492 KB |
Output is correct |
12 |
Correct |
79 ms |
81492 KB |
Output is correct |
13 |
Correct |
909 ms |
81716 KB |
Output is correct |
14 |
Correct |
930 ms |
81712 KB |
Output is correct |
15 |
Correct |
901 ms |
81712 KB |
Output is correct |
16 |
Correct |
930 ms |
81940 KB |
Output is correct |
17 |
Correct |
111 ms |
81540 KB |
Output is correct |
18 |
Correct |
109 ms |
81520 KB |
Output is correct |
19 |
Correct |
100 ms |
81492 KB |
Output is correct |
20 |
Correct |
101 ms |
81532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
81420 KB |
Output is correct |
2 |
Correct |
55 ms |
81488 KB |
Output is correct |
3 |
Correct |
54 ms |
81472 KB |
Output is correct |
4 |
Correct |
57 ms |
81404 KB |
Output is correct |
5 |
Correct |
53 ms |
81492 KB |
Output is correct |
6 |
Correct |
52 ms |
81408 KB |
Output is correct |
7 |
Correct |
53 ms |
81420 KB |
Output is correct |
8 |
Correct |
55 ms |
81604 KB |
Output is correct |
9 |
Correct |
53 ms |
81372 KB |
Output is correct |
10 |
Correct |
53 ms |
81488 KB |
Output is correct |
11 |
Correct |
54 ms |
81656 KB |
Output is correct |
12 |
Correct |
53 ms |
81432 KB |
Output is correct |
13 |
Correct |
66 ms |
81804 KB |
Output is correct |
14 |
Correct |
65 ms |
81492 KB |
Output is correct |
15 |
Correct |
70 ms |
81488 KB |
Output is correct |
16 |
Correct |
66 ms |
81568 KB |
Output is correct |
17 |
Correct |
56 ms |
81488 KB |
Output is correct |
18 |
Correct |
56 ms |
81748 KB |
Output is correct |
19 |
Correct |
56 ms |
81488 KB |
Output is correct |
20 |
Correct |
56 ms |
81488 KB |
Output is correct |
21 |
Correct |
61 ms |
81532 KB |
Output is correct |
22 |
Correct |
62 ms |
81492 KB |
Output is correct |
23 |
Correct |
63 ms |
81748 KB |
Output is correct |
24 |
Correct |
60 ms |
81436 KB |
Output is correct |
25 |
Correct |
62 ms |
81492 KB |
Output is correct |
26 |
Correct |
61 ms |
81500 KB |
Output is correct |
27 |
Correct |
61 ms |
81436 KB |
Output is correct |
28 |
Correct |
66 ms |
81492 KB |
Output is correct |
29 |
Correct |
62 ms |
81876 KB |
Output is correct |
30 |
Correct |
62 ms |
81476 KB |
Output is correct |
31 |
Correct |
311 ms |
81488 KB |
Output is correct |
32 |
Correct |
321 ms |
81748 KB |
Output is correct |
33 |
Correct |
309 ms |
81588 KB |
Output is correct |
34 |
Correct |
317 ms |
81752 KB |
Output is correct |
35 |
Correct |
304 ms |
81584 KB |
Output is correct |
36 |
Correct |
323 ms |
81596 KB |
Output is correct |
37 |
Correct |
309 ms |
81460 KB |
Output is correct |
38 |
Correct |
318 ms |
81420 KB |
Output is correct |
39 |
Correct |
314 ms |
81612 KB |
Output is correct |
40 |
Correct |
308 ms |
81552 KB |
Output is correct |
41 |
Correct |
260 ms |
81720 KB |
Output is correct |
42 |
Correct |
278 ms |
81716 KB |
Output is correct |
43 |
Correct |
247 ms |
81492 KB |
Output is correct |
44 |
Correct |
248 ms |
81704 KB |
Output is correct |
45 |
Correct |
275 ms |
81492 KB |
Output is correct |
46 |
Correct |
282 ms |
81716 KB |
Output is correct |
47 |
Correct |
268 ms |
81716 KB |
Output is correct |
48 |
Correct |
273 ms |
81720 KB |
Output is correct |
49 |
Correct |
61 ms |
81468 KB |
Output is correct |
50 |
Correct |
61 ms |
81492 KB |
Output is correct |
51 |
Correct |
78 ms |
81492 KB |
Output is correct |
52 |
Correct |
79 ms |
81492 KB |
Output is correct |
53 |
Correct |
909 ms |
81716 KB |
Output is correct |
54 |
Correct |
930 ms |
81712 KB |
Output is correct |
55 |
Correct |
901 ms |
81712 KB |
Output is correct |
56 |
Correct |
930 ms |
81940 KB |
Output is correct |
57 |
Correct |
111 ms |
81540 KB |
Output is correct |
58 |
Correct |
109 ms |
81520 KB |
Output is correct |
59 |
Correct |
100 ms |
81492 KB |
Output is correct |
60 |
Correct |
101 ms |
81532 KB |
Output is correct |
61 |
Correct |
52 ms |
81436 KB |
Output is correct |
62 |
Correct |
75 ms |
81460 KB |
Output is correct |
63 |
Correct |
2115 ms |
81768 KB |
Output is correct |
64 |
Correct |
2165 ms |
81748 KB |
Output is correct |
65 |
Correct |
2211 ms |
81748 KB |
Output is correct |
66 |
Correct |
2179 ms |
81732 KB |
Output is correct |
67 |
Correct |
2231 ms |
81992 KB |
Output is correct |
68 |
Correct |
2265 ms |
81864 KB |
Output is correct |
69 |
Correct |
2161 ms |
81996 KB |
Output is correct |
70 |
Correct |
2247 ms |
81760 KB |
Output is correct |
71 |
Correct |
147 ms |
81424 KB |
Output is correct |
72 |
Correct |
134 ms |
81576 KB |
Output is correct |
73 |
Correct |
303 ms |
81400 KB |
Output is correct |
74 |
Correct |
336 ms |
81584 KB |
Output is correct |
75 |
Execution timed out |
3066 ms |
81728 KB |
Time limit exceeded |
76 |
Halted |
0 ms |
0 KB |
- |