HDU 1018 Big Number math problem

Source: Internet
Author: User
Tags integer numbers

Problem DescriptionIn Many applications very large integers numbers are required. Some of these applications is using keys for secure transmission of data, encryption, etc. In this problem you is given a number, you has to determine the number of digits in the factorial of the number. Inputinput consists of several lines of integer numbers. The first line contains a integer n, which is the number of cases to being tested, followed by n lines, one integer 1≤n≤ 107 on all line. Outputthe output contains the number of digits in the factorial of the integers appearing in the input. Sample Input21020 Sample Output719 The topic meaning is to give you a number, to find out how many of the number of factorial.  Here need to use a logarithmic knowledge of 1.  The logarithm of a number for 10 is the number of digits 2. LOG10 (x*y) =log (x) +log (y) know the above two, the topic is quite simple. The code is as follows
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <iostream>5 using namespacestd;6 intN;7 intMain () {8scanf"%d",&n);9      while(n--)Ten     {    One         intT; Ascanf"%d",&t); -         intans=0; -         Doublek=0; the          for(intI=1; i<=t;++i) -         { -k+=log10 (i); -         } +Ans= (int) K +1; -printf"%d\n", ans); +     } A     return 0; at}

HDU 1018 Big number math problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.