当前位置:网站首页>520 diamond Championship 7-4 7-7 solution
520 diamond Championship 7-4 7-7 solution
2022-07-05 08:51:00 【Qizi K】
Mengxin came to write the solution again
These two questions can be used “ Stack ” To operate the problem ~
7-7 Non zero mantissa of factorials (20 branch )
seek N The first non-zero at the end of the factorial K digit , At the same time, how many zeros are there at the end of the output .
Ideas : Just simulate ~k No more than 9 So use long long that will do . Each simulation takes the last few digits of the operation result ( Because no matter how large the number of digits is, it will not affect the subsequent results ).
P.S. In fact, the number of zeros only needs to be seen 5 How many multiples of ( Because at the end 0 Several heels 2 and 5 The multiple of and 5 Is far less than 2 Multiple But since it is time and time again There is no need to calculate the number of zeros at the end alone See code for details )
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e13;
int main(){
int n, k;
cin >> n >> k;
ll now = 1;
int cnt = 0;
for (int i = 1; i <= n; i++){
now *= i;
while (now % 10 == 0){
now /= 10;
cnt++;
}
now %= mod;
}
stack<int> st;
while (k--){
st.push(now % 10);
now /= 10;
}
while (st.size()){
cout << st.top();
st.pop();
}
cout << " " << cnt << endl;
return 0;
}
7-4 Archaic style A+B (15 branch )
Similar to the previous question Use the stack to process each digit ~
For negative numbers , Output one more - No , Then it is converted to positive number processing ~
#include<cstdio>
#include<stack>
using namespace std;
stack<int> s;
int a,b,ans;
int main(){
scanf("%d%d",&a,&b);
ans = a + b;
if(ans < 0) printf("-\n"), ans = -ans;
do{
s.push(ans % 10);
}while(ans /= 10);
while(s.size()){
printf("%d\n",s.top());
s.pop();
}
return 0;
}
边栏推荐
- Halcon: check of blob analysis_ Blister capsule detection
- Yolov4 target detection backbone
- kubeadm系列-01-preflight究竟有多少check
- AdaBoost use
- Xrosstools tool installation for X-Series
- Business modeling | process of software model
- Run menu analysis
- 【日常训练--腾讯精选50】557. 反转字符串中的单词 III
- Wechat H5 official account to get openid climbing account
- Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
猜你喜欢

Guess riddles (6)

How to manage the performance of R & D team?

Numpy pit: after the addition of dimension (n, 1) and dimension (n,) array, the dimension becomes (n, n)

猜谜语啦(8)

C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)

AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解

EA introduction notes

Halcon shape_ trans

Low code platform | apaas platform construction analysis

Guess riddles (5)
随机推荐
One dimensional vector transpose point multiplication np dot
Programming implementation of subscriber node of ROS learning 3 subscriber
Install the CPU version of tensorflow+cuda+cudnn (ultra detailed)
ORACLE进阶(三)数据字典详解
Oracle advanced (III) detailed explanation of data dictionary
TypeScript手把手教程,简单易懂
Pytorch entry record
Wechat H5 official account to get openid climbing account
Meta tag details
ROS learning 1- create workspaces and function packs
Illustration of eight classic pointer written test questions
Programming implementation of ROS learning 6 -service node
猜谜语啦(11)
我从技术到产品经理的几点体会
图解八道经典指针笔试题
特征工程
C# LINQ源码分析之Count
Ros-10 roslaunch summary
Business modeling of software model | stakeholders
GEO数据库中搜索数据