1. 程式人生 > >hdu 6304 多校第一場 Chiaki Sequence Revisited

hdu 6304 多校第一場 Chiaki Sequence Revisited

//#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<stdlib.h>
#include<time.h> #include <iomanip> #define lowbit(x) (x&(-x)) #define inf 0x7fffffff #define linf 0x7fffffffffffffff #define mem(x,y) memset(x,y,sizeof(x)) #define fup(i,x,y) for(int i=(x);i<=(y);i++) #define fdn(i,x,y) for(int i=(x);i>=(y);i--) #define sp(x) setprecision(x) #define
sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m) #define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k) #define sld(n) scanf("%lld",&n) #define sldd(n,m) scanf("%lld%lld",&n,&m) #define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k) #define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m) #define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k) #define sc(n) scanf("%s",n) #define pf(x) printf("%d\n",x) #define pfl(x) printf("%lld\n",x) #define pff(x) printf("%lf\n",x) #define debug printf("!!\n"); #define N 100005 #define M 4000009 #define pi acos(-1) #define eps 1e-2 //cout.setf(ios::fixed); //freopen("out.txt","w",stdout);// freopen("in.txt","r",stdin); using namespace std; typedef long long ll; typedef double db; const int mod=1e9+7; ll p[105]; ll quick(ll a,ll b) { ll ans=1; while(b) { if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans; } ll inv,n; ll ok(ll x) { ll sum=0; fup(i,0,62) { if(p[i]>x) break; sum+=x/p[i]; if(sum>n-1) return 2; } if(sum==n-1) return 1; return 0; } void Solve() { sld(n); if(n==1) { puts("1"); return ; } ll l=max(1ll,n/2-30),r=min(n,n/2+30),mid; while(l<=r) { mid=(l+r)>>1; int f=ok(mid); if(f==2) r=mid-1; else if(f) break; else l=mid+1; } if(!ok(mid)) mid++; ll now=mid-1; ll ans=0,sum=0; for(int i=0;i<=62;i++) { if(p[i]>now) break; ll tp=now/p[i]; tp%=mod; ll res=(((p[i]%mod*(tp+1))%mod*tp)%mod*inv)%mod; ans=(ans+res)%mod; sum+=tp; } ll last=((n-1-sum)%mod*mid)%mod; ans=(ans+last)%mod; pfl((1+ans)%mod); } int main() { p[0]=1; fup(i,1,62) p[i]=p[i-1]*2; inv=(mod+1)/2; int T; scanf("%d",&T); while(T--) { Solve(); } return 0; } /* 3 11 23 UTC+7.0 */