计蒜客button 概率
中文题意不多说,这题主要是数据太大,无法递推,所以用欧拉常数来解决
对于调和级数1/1+1/2+...+1/n=ln(n)+C+1/(2*n),C为欧拉常数,再加上ceil向上取整就可以了
#include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.57721566490153286060651209 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pii pair<int,int> using namespace std; const double g=10.0,eps=1e-12; const int N=100000+10,maxn=200000+10,inf=0x3f3f3f3f; int main() { int t; scanf("%d",&t); while(t--) { double n; scanf("%lf",&n); if(n<10000000) { double ans=0; for(double i=1;i<=n;i++) ans+=1.0/i; ans*=n; printf("%lld\n",(ll)ceil(ans)); } else { ll ans=(ll)ceil(log(n)*n+1.0/2+n*C); printf("%lld\n",ans); } } return 0; } /******************** 4294967295 97744545478 ********************/