标签:
题目链接:
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
//#include <bits/stdc++.h> #include <vector> #include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; #define Riep(n) for(int i=1;i<=n;i++) #define Riop(n) for(int i=0;i<n;i++) #define Rjep(n) for(int j=1;j<=n;j++) #define Rjop(n) for(int j=0;j<n;j++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar()); for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + ‘0‘); putchar(‘\n‘); } const LL mod=1e9+7; const double PI=acos(-1.0); const LL inf=1e14; const int N=1e4+15; const int maxn=18; LL dp[70],L[70],ans,sum[70]; void Init() { dp[1]=1; L[1]=1; for(int i=2;i<70;++i) { dp[i]=2*dp[i-1]+L[i-1]+1; L[i]=2*L[i-1]+1; } } void dfs(LL x) { if(x<=0)return; for(int i=1;i<70;i++) { if(L[i]<=x&&L[i+1]>x) { ans+=dp[i]; x-=L[i]+1; ans+=x+1; break; } } dfs(x); } int main() { int t; read(t); LL m; Init(); while(t--) { ans=0; read(m); dfs(m); printf("%lld\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5595351.html