bool issqr(__int128_t x)//开方
{
__int128_t y=(__int128_t)ceil(sqrt((long double)x));
for(;y*y<=x;++y);
for(--y;y*y>x;--y);
return y*y==x;
}
bool iscub(__int128_t x)//三次方
{
__int128_t y=(__int128_t)ceil(pow((long double)x,1.0/3));
for(;y*y*y<=x;++y);
for(--y;y*y*y>x;--y);
return y*y*y==x;
}
int tot,pr[maxx],vis[maxx];
void init()//素数表 O(nsqrt(n))
{
for(int i=2;i
int d[maxx],pr[maxx],tot;
void init()
{
for(int i = 2; i < maxx; ++i)
{
if(!d[i])
pr[tot++] = d[i] = i;
for(int j = 0, k; (k = i * pr[j]) < maxx; ++j)
{
d[k] = pr[j];
if(d[i] == pr[j])
break;
}
}
}
const int s=10;//Miller-Rabin
inline LL mul_mod(LL a, LL b, LL m) O(n^(1/4))
{
LL c = a*b-(LL)((long double)a*b/m+0.5)*m;
return c<0 ? c+m : c;
}
LL fast_exp(LL a,LL x,LL m)
{
LL b = 1;
while (x)
{
if (x & 1)
b = mul_mod(b, a, m);
a = mul_mod(a, a, m);
x >>= 1;
}
return b;
}
bool MR(LL n)
{
if (!(n&1))
return n == 2;
LL t = 0, u;
for (u = n-1; !(u&1); u >>= 1)
++t;
for (int i = 0; i < s; ++i)
{
LL a = rand()%(n-2)+2, x = fast_exp(a, u, n);
for (LL j = 0, y; x != 1 && j < t; ++j, x = y)
{
y = mul_mod(x, x, n);
if (y == 1 && x != n-1)
return false;
}
if (x != 1)
return false;
}
return true;
}
Miller-Rabin Pollard-rho
#include
#include
#include
#include
typedef long long ll;
const int s = 10, MAX_F = 70;
ll cnt, f[MAX_F];
inline ll mul_mod(ll a, ll b, ll m)
{
ll c = a*b-(ll)((long double)a*b/m+0.5)*m;
return c<0 ? c+m : c;
}
ll fast_exp(ll a, ll x, ll m)
{
ll b = 1;
while (x)
{
if (x & 1)
b = mul_mod(b, a, m);
a = mul_mod(a, a, m);
x >>= 1;
}
return b;
}
bool MR(ll n)
{
if (!(n&1))
return n == 2;
ll t = 0, u;
for (u = n-1; !(u&1); u >>= 1)
++t;
for (int i = 0; i < s; ++i)
{
ll a = rand()%(n-2)+2, x = fast_exp(a, u, n);
for (ll j = 0, y; x != 1 && j < t; ++j, x = y)
{
y = mul_mod(x, x, n);
if (y == 1 && x != n-1)
return false;
}
if (x != 1)
return false;
}
return true;
}
inline ll abs(ll x)
{
return x<0 ? -x : x;
}
ll gcd(ll a, ll b)
{
return b ? gcd(b, a%b) : a;
}
ll PR(ll n, ll a)
{
ll x = rand()%n, y = x, k = 1, i = 0, d = 1;
while (d == 1)
{
if ((x = (mul_mod(x, x, n)+a)%n) == y)
return n;
d = gcd(n, abs(y-x));
if (++i == k)
{
k <<= 1;
y = x;
}
}
return d;
}
void decomp(ll n)
{
if (n == 1)
return;
if (MR(n))
{
f[cnt++] = n;
return;
}
ll d = n, c = n-1;
while (d == n)
d = PR(n, c--);
do
{
n /= d;
}
while (!(n%d));
decomp(d);
decomp(n);
}
int main()
{
srand(time(0));
ll n;
while (scanf("%lld", &n), n)
{
cnt = 0;
decomp(n);
std::sort(f, f+cnt);
cnt = std::unique(f, f+cnt)-f;
ll ans = n;
for (int i = 0; i < cnt; ++i)
{
// printf("%lld\n", f[i]);
ans = ans/f[i]*(f[i]-1);
}
printf("%lld\n", ans);
}
return 0;
}
快速乘
LL fun(LL a,LL b)
{
LL sum=0;
W(b)
{
if(b&1)
sum=(sum+a)%p;
b/=2;
a=a*2%p;
}
return sum;
}
快速幂
int _pow(LL a,LL n)
{
LL ret=1;
while(n)
{
if(n&1) ret=ret*a%mod;
a=a*a%mod;
n>>=1;
}
return ret;
}
int inv(int x)
{
return _pow(x,mod-2);
}
拓展gcd
void exgcd(ll a,ll b,ll &g,ll &x,ll &y)
{
if(!b) {g=a;x=1;y=0;}
else {exgcd(b,a%b,g,y,x);y-=x*(a/b);}
}
void work(ll a , ll b , ll d ,ll& g , ll& x , ll& y)
{
exgcd(a,b,g,x,y); //此处的x,y接收 ax+by=gcd(a,b)的值
x *= d/g; //求ax+by=c 的解x
int t = b/g;
x = (x%t + t) % t;
y = abs( (a*x - d) / b);
}
ll a,b,g,x,y,d;
void solve()
{
S_3(a,b,d);
work(a,b,d,g,x,y);
/* if(x==0)
{
for(int i=1;x<=0;i++)
{
x=x+b/g*i;
y=y-a/g*i;
}
}*/
}
逆元
void ex_gcd(LL a, LL b, LL &x, LL &y, LL &d)
{
if (!b) {d = a, x = 1, y = 0;}
else{
ex_gcd(b, a % b, y, x, d);
y -= x * (a / b);
}
}
LL inv2(LL t, LL p)
{//如果不存在,返回-1
LL d, x, y;
ex_gcd(t, p, x, y, d);
return d == 1 ? (x % p + p) % p : -1;
}
错排 排列组合
const int mod=1e9+7;
const int maxn=1e4+7;
LL D[maxn], C[maxn][105];
int p[1000050];
void init()
{
D[0]=1;D[1]=0;
for(int i=1;i
C(n,m)
先init 再comb(n,m) n在下
namespace COMB
{
int F[N<<1], Finv[N<<1], inv[N<<1];
void init()
{
inv[1] = 1;
for (int i = 2; i < N<<1; i++)
{
inv[i] = (LL)(MOD - MOD/i) * inv[MOD%i] % MOD;
}
F[0] = Finv[0] = 1;
for (int i = 1; i < N<<1; i++)
{
F[i] = (LL)F[i-1] * i % MOD;
Finv[i] = (LL)Finv[i-1] * inv[i] % MOD;
}
}
int comb(int n, int m)
{
if (m < 0 || m > n) return 0;
return (LL)F[n] * Finv[n-m] % MOD * Finv[m] % MOD;
}
}
using namespace COMB;
C(n,m) 不mod
double ln[3100000];
int n,p;
void init()
{
int maxc=3e6;
for(int i=1;i<=maxc;i++)
{
ln[i]=log(i);
}
}
db comb(int x,int y)
{
db ans=0;
for(int i=1;i<=y;i++)
{
ans+=ln[x-i+1]-ln[i];
}
return ans;
}
db calc(int x)
{
return x*exp(comb(n,p-1)-comb(n+x,p));
}
C(n,m) mod p (p为素数
//C(m,n) m在上 n在下,p为素数
LL n,m,p;
LL quick_mod(LL a, LL b)
{
LL ans = 1;
a %= p;
while(b)
{
if(b & 1)
{
ans = ans * a % p;
b--;
}
b >>= 1;
a = a * a % p;
}
return ans;
}
LL C(LL n, LL m)
{
if(m > n) return 0;
LL ans = 1;
for(int i=1; i<=m; i++)
{
LL a = (n + i - m) % p;
LL b = i % p;
ans = ans * (a * quick_mod(b, p-2) % p) % p;
}
return ans;
}
LL Lucas(LL n, LL m)
{
if(m == 0) return 1;
return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
int main()
{
int T;
scan_d(T);
while(T--)
{
scan_d(n),scan_d(m),scan_d(p);
print(Lucas(n,m));
}
return 0;
}
C(n,m) mod p (p可能为合数
const int N = 200005;
bool prime[N];
int p[N];
int cnt;
void isprime()
{
cnt = 0;
memset(prime,true,sizeof(prime));
for(int i=2; i>= 1;
a = a * a % m;
}
return ans;
}
LL Work(LL n,LL p)
{
LL ans = 0;
while(n)
{
ans += n / p;
n /= p;
}
return ans;
}
LL Solve(LL n,LL m,LL P)
{
LL ans = 1;
for(int i=0; i>T;
while(T--)
{
LL n,m,P;
cin>>n>>m>>P;
n += m - 2;
m--;
cout<
FFT:
//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include
#include
#include
#include
因子分解--3:
LL F(LL a,LL i)
{
LL l=1,r=a,b;
W(l
一个数因子数和:
#include
#include
#include
#include
#include
#include
baby-step A^x=B(mod c)
#include
#include
#include
#include
#include
#define LL __int64
#define N 1000000
using namespace std;
struct Node
{
int idx;
int val;
} baby[N];
bool cmp(Node n1,Node n2)
{
return n1.val!=n2.val?n1.val>=1;
}
return (int)ret;
}
int BinSearch(int num,int m)
{
int low=0,high=m-1,mid;
while(low<=high)
{
mid=(low+high)>>1;
if(baby[mid].val==num)
return baby[mid].idx;
if(baby[mid].val=0)
{
int pos=BinSearch(tmp,cnt);
if(pos!=-1)
return i*m+pos+d;
}
}
return -1;
}
int main()
{
int A,B,C;
while(scanf("%d%d%d",&A,&C,&B)!=EOF)
{
if(B>=C)
{
puts("Orz,I can’t find D!");
continue;
}
int ans=BabyStep(A,B,C);
if(ans==-1)
puts("Orz,I can’t find D!");
else
printf("%d\n",ans);
}
return 0;
}
找中位数:
if(n%2) {
int mid=(n+1)>>1;
nth_element(a+1,a+mid,a+1+n);
pf("%d",a[mid]);
}
莫比乌斯:
int tot,p[maxx],miu[maxx],v[maxx];
void Mobius(int n)
{
int i,j;
for(miu[1]=1,i=2;i<=n;i++)
{
if(!v[i]) p[tot++]=i,miu[i]=-1;
for(j=0;j
递推式
#include
#include
#include
#include
#include
#include
#include
求一个数的所有因子和
#include
const int maxn = 500000+2;
int sum[maxn];
int main()
{
for(int i=1; i
1-n 素数个数
//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include
#include
#include
#include
大数:
#include
#include
#include
using namespace std;
#define DIGIT 4 //四位隔开,即万进制
#define DEPTH 10000 //万进制
#define MAX 25100 //题目最大位数/4,要不大直接设为最大位数也行
typedef int bignum_t[MAX+1];
int read(bignum_t a,istream&is=cin)
{
char buf[MAX*DIGIT+1],ch ;
int i,j ;
memset((void*)a,0,sizeof(bignum_t));
if(!(is>>buf))return 0 ;
for(a[0]=strlen(buf),i=a[0]/2-1;i>=0;i--)
ch=buf[i],buf[i]=buf[a[0]-1-i],buf[a[0]-1-i]=ch ;
for(a[0]=(a[0]+DIGIT-1)/DIGIT,j=strlen(buf);j1;a[0]--);
return 1 ;
}
void write(const bignum_t a,ostream&os=cout)
{
int i,j ;
for(os<=DEPTH;c[c[0]+1]=c[c[0]]/DEPTH,c[c[0]]%=DEPTH,c[0]++);
return comp(a,c);
}
int comp(const bignum_t a,const int c,const int d,const bignum_t b)
{
int i,t=0,O=-DEPTH*2 ;
if(b[0]-a[0]d;i--)
{
t=t*DEPTH+a[i-d]*c-b[i];
if(t>0)return 1 ;
if(t0)return 1 ;
if(t0 ;
}
void add(bignum_t a,const bignum_t b)
{
int i ;
for(i=1;i<=b[0];i++)
if((a[i]+=b[i])>=DEPTH)
a[i]-=DEPTH,a[i+1]++;
if(b[0]>=a[0])
a[0]=b[0];
else
for(;a[i]>=DEPTH&&i0);
}
void add(bignum_t a,const int b)
{
int i=1 ;
for(a[1]+=b;a[i]>=DEPTH&&i=DEPTH;a[a[0]+1]=a[a[0]]/DEPTH,a[a[0]]%=DEPTH,a[0]++);
}
void sub(bignum_t a,const bignum_t b)
{
int i ;
for(i=1;i<=b[0];i++)
if((a[i]-=b[i])<0)
a[i+1]--,a[i]+=DEPTH ;
for(;a[i]<0;a[i]+=DEPTH,i++,a[i]--);
for(;!a[a[0]]&&a[0]>1;a[0]--);
}
void sub(bignum_t a,const int b)
{
int i=1 ;
for(a[1]-=b;a[i]<0;a[i+1]+=(a[i]-DEPTH+1)/DEPTH,a[i]-=(a[i]-DEPTH+1)/DEPTH*DEPTH,i++);
for(;!a[a[0]]&&a[0]>1;a[0]--);
}
void sub(bignum_t a,const bignum_t b,const int c,const int d)
{
int i,O=b[0]+d ;
for(i=1+d;i<=O;i++)
if((a[i]-=b[i-d]*c)<0)
a[i+1]+=(a[i]-DEPTH+1)/DEPTH,a[i]-=(a[i]-DEPTH+1)/DEPTH*DEPTH ;
for(;a[i]<0;a[i+1]+=(a[i]-DEPTH+1)/DEPTH,a[i]-=(a[i]-DEPTH+1)/DEPTH*DEPTH,i++);
for(;!a[a[0]]&&a[0]>1;a[0]--);
}
void mul(bignum_t c,const bignum_t a,const bignum_t b)
{
int i,j ;
memset((void*)c,0,sizeof(bignum_t));
for(c[0]=a[0]+b[0]-1,i=1;i<=a[0];i++)
for(j=1;j<=b[0];j++)
if((c[i+j-1]+=a[i]*b[j])>=DEPTH)
c[i+j]+=c[i+j-1]/DEPTH,c[i+j-1]%=DEPTH ;
for(c[0]+=(c[c[0]+1]>0);!c[c[0]]&&c[0]>1;c[0]--);
}
void mul(bignum_t a,const int b)
{
int i ;
for(a[1]*=b,i=2;i<=a[0];i++)
{
a[i]*=b ;
if(a[i-1]>=DEPTH)
a[i]+=a[i-1]/DEPTH,a[i-1]%=DEPTH ;
}
for(;a[a[0]]>=DEPTH;a[a[0]+1]=a[a[0]]/DEPTH,a[a[0]]%=DEPTH,a[0]++);
for(;!a[a[0]]&&a[0]>1;a[0]--);
}
void mul(bignum_t b,const bignum_t a,const int c,const int d)
{
int i ;
memset((void*)b,0,sizeof(bignum_t));
for(b[0]=a[0]+d,i=d+1;i<=b[0];i++)
if((b[i]+=a[i-d]*c)>=DEPTH)
b[i+1]+=b[i]/DEPTH,b[i]%=DEPTH ;
for(;b[b[0]+1];b[0]++,b[b[0]+1]=b[b[0]]/DEPTH,b[b[0]]%=DEPTH);
for(;!b[b[0]]&&b[0]>1;b[0]--);
}
void div(bignum_t c,bignum_t a,const bignum_t b)
{
int h,l,m,i ;
memset((void*)c,0,sizeof(bignum_t));
c[0]=(b[0]>1;h>l;m=(h+l+1)>>1)
if(comp(b,m,i-1,a))h=m-1 ;
else l=m ;
for(;!c[c[0]]&&c[0]>1;c[0]--);
c[0]=c[0]>1?c[0]:1 ;
}
void div(bignum_t a,const int b,int&c)
{
int i ;
for(c=0,i=a[0];i;c=c*DEPTH+a[i],a[i]=c/b,c%=b,i--);
for(;!a[a[0]]&&a[0]>1;a[0]--);
}
void sqrt(bignum_t b,bignum_t a)
{
int h,l,m,i ;
memset((void*)b,0,sizeof(bignum_t));
for(i=b[0]=(a[0]+1)>>1;i;sub(a,b,m,i-1),b[i]+=m,i--)
for(h=DEPTH-1,l=0,b[i]=m=(h+l+1)>>1;h>l;b[i]=m=(h+l+1)>>1)
if(comp(b,m,i-1,a))h=m-1 ;
else l=m ;
for(;!b[b[0]]&&b[0]>1;b[0]--);
for(i=1;i<=b[0];b[i++]>>=1);
}
int digit(const bignum_t a,const int b)
{
int i,ret ;
for(ret=a[(b-1)/DIGIT+1],i=(b-1)%DIGIT;i;ret/=10,i--);
return ret%10 ;
}
#define SGN(x) ((x)>0?1:((x)<0?-1:0))
#define ABS(x) ((x)>0?(x):-(x))
int read(bignum_t a,int&sgn,istream&is=cin)
{
char str[MAX*DIGIT+2],ch,*buf ;
int i,j ;
memset((void*)a,0,sizeof(bignum_t));
if(!(is>>str))return 0 ;
buf=str,sgn=1 ;
if(*buf=='-')sgn=-1,buf++;
for(a[0]=strlen(buf),i=a[0]/2-1;i>=0;i--)
ch=buf[i],buf[i]=buf[a[0]-1-i],buf[a[0]-1-i]=ch ;
for(a[0]=(a[0]+DIGIT-1)/DIGIT,j=strlen(buf);j1;a[0]--);
if(a[0]==1&&!a[1])sgn=0 ;
return 1 ;
}
struct bignum
{
bignum_t num ;
int sgn ;
public :
inline bignum()
{
memset(num,0,sizeof(bignum_t));
num[0]=1 ;
sgn=0 ;
}
inline int operator!()
{
return num[0]==1&&!num[1];
}
inline bignum&operator=(const bignum&a)
{
memcpy(num,a.num,sizeof(bignum_t));
sgn=a.sgn ;
return*this ;
}
inline bignum&operator=(const int a)
{
memset(num,0,sizeof(bignum_t));
num[0]=1 ;
sgn=SGN (a);
add(num,sgn*a);
return*this ;
}
;
inline bignum&operator+=(const bignum&a)
{
if(sgn==a.sgn)add(num,a.num);
else if
(sgn&&a.sgn)
{
int ret=comp(num,a.num);
if(ret>0)sub(num,a.num);
else if(ret<0)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memcpy(num,a.num,sizeof(bignum_t));
sub (num,t);
sgn=a.sgn ;
}
else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;
}
else if(!sgn)
memcpy(num,a.num,sizeof(bignum_t)),sgn=a.sgn ;
return*this ;
}
inline bignum&operator+=(const int a)
{
if(sgn*a>0)add(num,ABS(a));
else if(sgn&&a)
{
int ret=comp(num,ABS(a));
if(ret>0)sub(num,ABS(a));
else if(ret<0)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memset(num,0,sizeof(bignum_t));
num[0]=1 ;
add(num,ABS (a));
sgn=-sgn ;
sub(num,t);
}
else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;
}
else if
(!sgn)sgn=SGN(a),add(num,ABS(a));
return*this ;
}
inline bignum operator+(const bignum&a)
{
bignum ret ;
memcpy(ret.num,num,sizeof (bignum_t));
ret.sgn=sgn ;
ret+=a ;
return ret ;
}
inline bignum operator+(const int a)
{
bignum ret ;
memcpy(ret.num,num,sizeof (bignum_t));
ret.sgn=sgn ;
ret+=a ;
return ret ;
}
inline bignum&operator-=(const bignum&a)
{
if(sgn*a.sgn<0)add(num,a.num);
else if
(sgn&&a.sgn)
{
int ret=comp(num,a.num);
if(ret>0)sub(num,a.num);
else if(ret<0)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memcpy(num,a.num,sizeof(bignum_t));
sub(num,t);
sgn=-sgn ;
}
else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;
}
else if(!sgn)add (num,a.num),sgn=-a.sgn ;
return*this ;
}
inline bignum&operator-=(const int a)
{
if(sgn*a<0)add(num,ABS(a));
else if(sgn&&a)
{
int ret=comp(num,ABS(a));
if(ret>0)sub(num,ABS(a));
else if(ret<0)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memset(num,0,sizeof(bignum_t));
num[0]=1 ;
add(num,ABS(a));
sub(num,t);
sgn=-sgn ;
}
else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;
}
else if
(!sgn)sgn=-SGN(a),add(num,ABS(a));
return*this ;
}
inline bignum operator-(const bignum&a)
{
bignum ret ;
memcpy(ret.num,num,sizeof(bignum_t));
ret.sgn=sgn ;
ret-=a ;
return ret ;
}
inline bignum operator-(const int a)
{
bignum ret ;
memcpy(ret.num,num,sizeof(bignum_t));
ret.sgn=sgn ;
ret-=a ;
return ret ;
}
inline bignum&operator*=(const bignum&a)
{
bignum_t t ;
mul(t,num,a.num);
memcpy(num,t,sizeof(bignum_t));
sgn*=a.sgn ;
return*this ;
}
inline bignum&operator*=(const int a)
{
mul(num,ABS(a));
sgn*=SGN(a);
return*this ;
}
inline bignum operator*(const bignum&a)
{
bignum ret ;
mul(ret.num,num,a.num);
ret.sgn=sgn*a.sgn ;
return ret ;
}
inline bignum operator*(const int a)
{
bignum ret ;
memcpy(ret.num,num,sizeof (bignum_t));
mul(ret.num,ABS(a));
ret.sgn=sgn*SGN(a);
return ret ;
}
inline bignum&operator/=(const bignum&a)
{
bignum_t t ;
div(t,num,a.num);
memcpy (num,t,sizeof(bignum_t));
sgn=(num[0]==1&&!num[1])?0:sgn*a.sgn ;
return*this ;
}
inline bignum&operator/=(const int a)
{
int t ;
div(num,ABS(a),t);
sgn=(num[0]==1&&!num [1])?0:sgn*SGN(a);
return*this ;
}
inline bignum operator/(const bignum&a)
{
bignum ret ;
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
div(ret.num,t,a.num);
ret.sgn=(ret.num[0]==1&&!ret.num[1])?0:sgn*a.sgn ;
return ret ;
}
inline bignum operator/(const int a)
{
bignum ret ;
int t ;
memcpy(ret.num,num,sizeof(bignum_t));
div(ret.num,ABS(a),t);
ret.sgn=(ret.num[0]==1&&!ret.num[1])?0:sgn*SGN(a);
return ret ;
}
inline bignum&operator%=(const bignum&a)
{
bignum_t t ;
div(t,num,a.num);
if(num[0]==1&&!num[1])sgn=0 ;
return*this ;
}
inline int operator%=(const int a)
{
int t ;
div(num,ABS(a),t);
memset(num,0,sizeof (bignum_t));
num[0]=1 ;
add(num,t);
return t ;
}
inline bignum operator%(const bignum&a)
{
bignum ret ;
bignum_t t ;
memcpy(ret.num,num,sizeof(bignum_t));
div(t,ret.num,a.num);
ret.sgn=(ret.num[0]==1&&!ret.num [1])?0:sgn ;
return ret ;
}
inline int operator%(const int a)
{
bignum ret ;
int t ;
memcpy(ret.num,num,sizeof(bignum_t));
div(ret.num,ABS(a),t);
memset(ret.num,0,sizeof(bignum_t));
ret.num[0]=1 ;
add(ret.num,t);
return t ;
}
inline bignum&operator++()
{
*this+=1 ;
return*this ;
}
inline bignum&operator--()
{
*this-=1 ;
return*this ;
}
;
inline int operator>(const bignum&a)
{
return sgn>0?(a.sgn>0?comp(num,a.num)>0:1):(sgn<0?(a.sgn<0?comp(num,a.num)<0:0):a.sgn<0);
}
inline int operator>(const int a)
{
return sgn>0?(a>0?comp(num,a)>0:1):(sgn<0?(a<0?comp(num,-a)<0:0):a<0);
}
inline int operator>=(const bignum&a)
{
return sgn>0?(a.sgn>0?comp(num,a.num)>=0:1):(sgn<0?(a.sgn<0?comp(num,a.num)<=0:0):a.sgn<=0);
}
inline int operator>=(const int a)
{
return sgn>0?(a>0?comp(num,a)>=0:1):(sgn<0?(a<0?comp(num,-a)<=0:0):a<=0);
}
inline int operator<(const bignum&a)
{
return sgn<0?(a.sgn<0?comp(num,a.num)>0:1):(sgn>0?(a.sgn>0?comp(num,a.num)<0:0):a.sgn>0);
}
inline int operator<(const int a)
{
return sgn<0?(a<0?comp(num,-a)>0:1):(sgn>0?(a>0?comp(num,a)<0:0):a>0);
}
inline int operator<=(const bignum&a)
{
return sgn<0?(a.sgn<0?comp(num,a.num)>=0:1):(sgn>0?(a.sgn>0?comp(num,a.num)<=0:0):a.sgn>=0);
}
inline int operator<=(const int a)
{
return sgn<0?(a<0?comp(num,-a)>=0:1):
(sgn>0?(a>0?comp(num,a)<=0:0):a>=0);
}
inline int operator==(const bignum&a)
{
return(sgn==a.sgn)?!comp(num,a.num):0 ;
}
inline int operator==(const int a)
{
return(sgn*a>=0)?!comp(num,ABS(a)):0 ;
}
inline int operator!=(const bignum&a)
{
return(sgn==a.sgn)?comp(num,a.num):1 ;
}
inline int operator!=(const int a)
{
return(sgn*a>=0)?comp(num,ABS(a)):1 ;
}
inline int operator[](const int a)
{
return digit(num,a);
}
friend inline istream&operator>>(istream&is,bignum&a)
{
read(a.num,a.sgn,is);
return is ;
}
friend inline ostream&operator<<(ostream&os,const bignum&a)
{
if(a.sgn<0)
os<<'-' ;
write(a.num,os);
return os ;
}
};
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
bignum jie,ans;
jie+=1;
for(int i=1;i<=n;i++)
{
jie*=i;
}
for(int i=1;i<=n;i++)
{
ans=ans+jie/i;
}
cout<