当前位置:网站首页>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;
}
边栏推荐
- ABC#237 C
- Characteristic Engineering
- GEO数据库中搜索数据
- Use arm neon operation to improve memory copy speed
- Array, date, string object method
- How can fresh students write resumes to attract HR and interviewers
- Business modeling | process of software model
- Several problems to be considered and solved in the design of multi tenant architecture
- Redis implements a high-performance full-text search engine -- redisearch
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
猜你喜欢

319. 灯泡开关

Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc

My university

Xrosstools tool installation for X-Series
![[牛客网刷题 Day4] JZ35 复杂链表的复制](/img/bc/ce90bb3cb6f52605255f1d6d6894b0.png)
[牛客网刷题 Day4] JZ35 复杂链表的复制

Guess riddles (3)

Business modeling of software model | stakeholders
![[daiy4] copy of JZ35 complex linked list](/img/bc/ce90bb3cb6f52605255f1d6d6894b0.png)
[daiy4] copy of JZ35 complex linked list

Mathematical modeling: factor analysis

EA introduction notes
随机推荐
ROS learning 4 custom message
Halcon Chinese character recognition
Guess riddles (11)
Guess riddles (4)
kubeadm系列-00-overview
Several problems to be considered and solved in the design of multi tenant architecture
Characteristic Engineering
Beautiful soup parsing and extracting data
Guess riddles (142)
Ecmascript6 introduction and environment construction
Meta标签详解
The location search property gets the login user name
[matlab] matlab reads and writes Excel
Programming implementation of ROS learning 2 publisher node
Adaboost使用
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
ECMAScript6介绍及环境搭建
猜谜语啦(11)
Solutions of ordinary differential equations (2) examples
[牛客网刷题 Day4] JZ32 从上往下打印二叉树