当前位置:网站首页>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;
}
边栏推荐
- ORACLE进阶(三)数据字典详解
- C [essential skills] use of configurationmanager class (use of file app.config)
- Guess riddles (9)
- Typical low code apaas manufacturer cases
- 猜谜语啦(5)
- MPSoC QSPI flash upgrade method
- [Niuke brush questions day4] jz55 depth of binary tree
- 猜谜语啦(2)
- 【日常訓練--騰訊精選50】557. 反轉字符串中的單詞 III
- Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
猜你喜欢

Halcon shape_ trans

整形的分类:short in long longlong

319. 灯泡开关

Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)

猜谜语啦(10)

Business modeling of software model | vision

Classification of plastic surgery: short in long long long

Halcon snap, get the area and position of coins

Business modeling | process of software model

资源变现小程序添加折扣充值和折扣影票插件
随机推荐
猜谜语啦(4)
【日常训练】1200. 最小绝对差
Explore the authentication mechanism of StarUML
Search data in geo database
Yolov4 target detection backbone
Task failed task_ 1641530057069_ 0002_ m_ 000000
ORACLE进阶(三)数据字典详解
The location search property gets the login user name
多元线性回归(梯度下降法)
某公司文件服务器迁移方案
ROS learning 4 custom message
Halcon blob analysis (ball.hdev)
Tips 1: Web video playback code
Infix expression evaluation
Typescript hands-on tutorial, easy to understand
使用arm Neon操作,提高内存拷贝速度
696. Count binary substring
Bit operation related operations
Kubedm series-00-overview
Business modeling of software model | stakeholders