题目链接
https://ac.nowcoder.com/acm/contest/5881/B
解题思路
五进制思想,一位数有5^1个,两位数有5^2个,……
注意一下,--num!!!让取余操作变得随心所欲,尽量记住这个方法!!!
AC代码
仿写大佬代码
#include<bits/stdc++.h> #define ll long long using namespace std; const int N=110; const ll mod=1e9+7; char mp[]="12359"; ll t,n,m; ll fac[N]; void Create(){ fac[0]=fac[1]=1; for(int i=1;i<=N;i++) fac[i]=fac[i-1]*i%mod; } ll KSM(ll x,ll p){ ll ans=1; while(p){ if(p&1LL) ans=ans*x%mod; x=x*x%mod; p>>=1; } return ans; } ll C(ll n,ll m){ return fac[n]*KSM(fac[m],mod-2)%mod*KSM(fac[n-m],mod-2)%mod; } void Solve(){ cin>>t; while(t--){ cin>>n>>m; ll num=C(n,m); string ans; while(num>0){ --num; ans+=mp[num%5]; num/=5; } reverse(ans.begin(),ans.end()); cout<<ans<<endl; } } int main(){ Create(); Solve(); return 0; }