QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136817 | #241. Chiaki Sequence Revisited | S_Explosion# | 100 ✓ | 39ms | 3392kb | C++20 | 1.2kb | 2023-08-09 12:03:33 | 2023-08-09 12:03:37 |
Judging History
answer
#include <bits/stdc++.h>
#define hh puts("")
#define pc putchar
#define int long long
#define P 1000000007
using namespace std;
int n,dp[100],f[100],a[10000005],b[10000005];
inline int read() {
int x = 0;
bool f = true; char ch = getchar();
for ( ; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-';
for ( ; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48);
return x = f ? x : -x;
}
void write(int x){if(x<0){pc('-'),x=-x;}if(x>9)write(x/10);pc(x%10+48);}
void writeln(int x){write(x),hh;}
signed main(){
dp[1]=1;
f[1]=1;
// a[1]=a[2]=1;
// for(int i=3;i<=10000000;i++) a[i]=a[i-a[i-1]]+a[i-1-a[i-2]];
// for(int i=1;i<=10000000;i++) b[i]=(b[i-1]+a[i])%P;
for(int i=2;i<=63;i++){
dp[i]=dp[i-1]*2+1;
f[i]=(f[i-1]*2%P+(1ll<<(i-2))%P*(dp[i-1]%P)%P+(1ll<<(i-1))%P)%P;
}
int T=read();
while(T--){
n=read()-1;
int ans=0;
for(int i=63;i>=1;i--){
if(n>=dp[i]){
n-=dp[i];
ans=(ans+f[i]+(n%P)*((1ll<<(i-1))%P)%P)%P;
}
}
ans=(ans+n+1)%P;
writeln(ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 39ms
memory: 3392kb
input:
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1 2 4 6 9 13 17 21 26 32 38 45 53 61 69 77 86 96 106 117 129 141 153 166 180 194 209 225 241 257 273 289 306 324 342 361 381 401 421 442 464 486 509 533 557 581 605 630 656 682 709 737 765 793 822 852 882 913 945 977 1009 1041 1073 1105 1138 1172 1206 1241 1277 1313 1349 1386 1424 1462 1501 1541 158...
result:
ok 100000 lines