Factorial of large numbers of digits

Problem C: factorial median
time limit: 1 Sec Memory Limit: 128 MB
[submit] [state]
title described
in many software need to use a larger integer. For example, some software will be used in large numbers or cryptographic key transfer of data security and so on. In this problem, according to the number of bits you want to give your integer to calculate the factorial of the number.
Input
containing an integer number of lines. First row n, represents the number of cases, followed by n lines, each line an integer m (1≤m≤10 ^ 7).
Output
output bits factorial of these numbers.
Sample input the Copy
2
10
20 is
sample output the Copy
. 7
. 19

#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int M = 100005;
long long count(int x){
    long long ans = 1;
    double k = 1.0;
    for(int i=1; i<=x; i++){
        k *= i;
        while(k>=10){
            ans++;
            k/=10;
        }
    }
    return ans;
}
int main()
{
    int n,m;
    
    cin >> n;
    while(n--){
        cin >> m;
        cout << count(m) << endl;
    }
    return 0;
}


Published 62 original articles · won praise 0 · Views 1759

Guess you like

Origin blog.csdn.net/jhckii/article/details/104248246