P1591 阶乘数码

// Problem: P1591 阶乘数码
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1591
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn
#include <bits/stdc++.h>
using namespace std;
vector<int> mulByI(vector<int> a, int b) {
vector<int> res;
int pre = 0;
for (int i = 0; i < a.size(); ++i) {
pre += a[i] * b;
res.push_back(pre % 10);
pre /= 10;
}
while (pre) {
res.push_back(pre % 10);
pre /= 10;
}
return res;
}
vector<int> getRes(int n) {
vector<int> res(1, 1);
for (int i = 1; i <= n; ++i) {
res = mulByI(res, i);
}
return res;
}
int main() {
int t;
cin >> t;
while (t--) {
int n, a;
cin >> n >> a;
vector<int> res = getRes(n);
long long cnt = 0;
for (auto i : res) {
if (i == a) {
++cnt;
}
}
cout << cnt << endl;
}
return 0;
}
posted @   Pannnn  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
-->
点击右上角即可分享
微信分享提示