腾讯云建站多少钱,中国建设银行官方网站网上银行,网站搜索优化排名,怎么建设网站让国外看题目描述 n的阶乘定义为n!n*(n -1)* (n - 2)* ...* 1。n的双阶乘定义为n!!n*(n -2)* (n -4)* ...* 2或n!!n(n - 2)*(n - 4)* ...* 1取决于n的奇偶性#xff0c;但是阶乘的增长速度太快了#xff0c;所以我们现在只想知道n!和n!!末尾的的个数 输入格式
一个正整数n #xff…题目描述 n的阶乘定义为n!n*(n -1)* (n - 2)* ...* 1。n的双阶乘定义为n!!n*(n -2)* (n -4)* ...* 2或n!!n(n - 2)*(n - 4)* ...* 1取决于n的奇偶性但是阶乘的增长速度太快了所以我们现在只想知道n!和n!!末尾的的个数 输入格式
一个正整数n n ) 输出格式 两个整数分别为n!和n!!末尾0的个数
样例输入#1
10
样例输出#1
2 1
样例输入#2
5
样例输出#2
1 0
参考代码
#include iostream
#include cstdio
#define ll long long
using namespace std;int main()
{freopen(factorial.in, r, stdin); //此处为海淀区赛指定文件名freopen(factorial.out, w, stdout);//考场代码必须加文件输入输出ll n, cnt_5, cnt_2;scanf(%lld, n);cnt_5 cnt_2 0;for(ll i 1; i n; i){ll tmp i;while(tmp % 5 0){cnt_5;tmp / 5;}tmp i;while(tmp % 2 0){cnt_2;tmp / 2;}}printf(%lld , min(cnt_2, cnt_5));cnt_5 cnt_2 0;if(n % 2 ! 0){for(ll i n; i 1; i - 2){ll tmp i;while(tmp % 5 0){cnt_5;tmp / 5;}tmp i;while(tmp % 2 0){cnt_2;tmp / 2;}}}else{for(ll i n; i 2; i - 2){ll tmp i;while(tmp % 5 0){cnt_5;tmp / 5;}tmp i;while(tmp % 2 0){cnt_2;tmp / 2;}}}printf(%lld, min(cnt_5, cnt_2));return 0;
}