QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136722#241. Chiaki Sequence RevisitedRd_rainydays#0 19ms3660kbC++20934b2023-08-09 10:33:022023-08-09 10:33:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 10:33:03]
  • 评测
  • 测评结果:0
  • 用时:19ms
  • 内存:3660kb
  • [2023-08-09 10:33:02]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll mod=1000000007;
ll calc(ll x){
  ll res=0;
  while(x>0){
   res=res+x;
   x/=2;
  }
  return res;
}
ll solve(ll n){
  ll l=n/2,r=r,mid,ans=r;
  while(l<=r){
     mid=(l+r)/2;
     if(calc(mid)>=n)ans=mid,r=mid-1;
     else l=mid+1;
  }
  return ans;
}
ll Ko_ye(ll n){
  if(n==0)return 0;
  if(n==1)return 1;
  ll res=0;
  if(n%2==0)res=(n/2)%mod*((n+1)%mod)%mod;
  else res=(((n+1)/2)%mod)*(n%mod)%mod;
  return (res+2*Ko_ye(n/2))%mod;
}
int T;
int main(){
  scanf("%d",&T);
  while(T--){
    // cout<<"???"<<calc(2)<<endl;
    ll n;
    scanf("%lld",&n);
    if(n==1){puts("1");}
    else{
      n--;
    ll K=solve(n);
    // cout<<K<<endl;
    ll ans=(n-calc(K-1))%mod*(K%mod)%mod;
    ans=(ans+Ko_ye(K-1))%mod;
    printf("%lld\n",(ans+1)%mod);
    }
  }
}

详细

Test #1:

score: 0
Wrong Answer
time: 19ms
memory: 3660kb

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 2nd lines differ - expected: '2', found: '1'