Hayaizo @ 2022-10-22 11:34:58
#include<iostream>
#include<string>
using namespace std;
int n, num, a;
int arr[10000000];
int number;
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num >> a;
arr[10000000] = { 0 };
arr[0] = { 1 };
for (int i = 1; i <= num; i++) {
for (int j = 0; j < 100;j++) {
arr[j] *= i;
}
for (int j = 0; j < 100; j++) {
if (arr[j] > 9) {
arr[j + 1] += arr[j] / 10;
arr[j] %= 10;
}
}
}
//删除前导0
int k = 0;
for (k = 100; k >= 0 && arr[k] == 0; k--) {
;
}
int cnt = 0;
for (int i = 0; i < k; i++) {
if (arr[i] == a) {
cnt++;
}
}
cout << cnt<<endl;
}
return 0;
}
by twrjx @ 2022-10-22 11:41:43
题号是什么
by OoXiao_QioO @ 2022-10-22 11:43:25
@twrjx P1591
by Hayaizo @ 2022-10-22 11:54:28
#include<iostream>
#include<string>
using namespace std;
int n, num, a;
int arr[10000];
int number;
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num >> a;
memset(arr, 0,sizeof(arr));
arr[0] = { 1 };
for (int i = 1; i <= num; i++) {
for (int j = 0; j < 100;j++) {
arr[j] *= i;
}
for (int j = 0; j < 100; j++) {
if (arr[j] > 9) {
arr[j + 1] += arr[j] / 10;
arr[j] %= 10;
}
}
}
//删除前导0
int k = 0;
for (k = 100; k >= 0 && arr[k] == 0; k--) {
;
}
int cnt = 0;
for (int i = 0; i <= k; i++) {
if (arr[i] == a) {
cnt++;
}
}
cout << cnt<<endl;
}
return 0;
}
改成这样也不行
by Lucas2024 @ 2022-10-24 20:39:36
#include<iostream>
#include<cstring>
using namespace std;
int a[2570],l,ans,t,n,m;
int main(){
int i,j;
cin>>t;
while(t){
t--;
cin>>n>>m;
ans=0;
memset(a,0,sizeof(a));
l=1;
a[0]=1;//初始化为1,不能为0,不然怎么乘都是0
for(i=2;i<=n;i++){
for(j=0;j<l;j++){
a[j]*=i;
}
for(j=0;j<l;j++){
if(a[j]>9){//进位
a[j+1]+=a[j]/10;
a[j]%=10;
}
}
while(a[l]!=0){//l+1若>0,长度++
if(a[l]>9){//再次判断进位
a[l+1]+=a[l]/10;
a[l]%=10;
}
l++;
}
}
while(l--){//当长度为0时,ans表示数字m的个数
if(a[l]==m){
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
/*
正确的