P1591 阶乘数码 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include <bits/stdc++.h>
#include <iostream>
#include<unordered_map>
#define x first
#define y second
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<LL,int> PLI ;
const int N = 2e6+10,M = 1000 * 100000 + 10 ,mod = 1000000007,INF1 = 0x3f3f3f3f;
const LL INF2 = 1e17;
int n,m;
vector<int> mul(vector<int> a,int b)
{
vector<int> c;
int t=0;
for(int i=0;i<a.size() || t ;i ++ )
{
if(i < a.size() )
t += a[i] * b;
c.push_back(t %10);t /=10;
}
while(c.size() > 1 && c.back() == 0 ) c.pop_back();
return c;
}
inline void solve()
{
cin>>n>>m;vector<int> a;
a.push_back(1);
for(int i=1;i<=n;i ++ )
{
a= mul(a,i);
}
LL ans=0;
for(int i=0;i<a.size() ;i ++ ) if(a[i] == m) ans ++ ;
cout << ans <<endl;
}
signed main()
{
ios
int T=1;
cin>>T;
while(T -- )
{
solve();
}
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)