hdu1492 (approximate number theorem)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1492

Here, let's talk about the theorem of number of numbers:

For positive integer x, decompose the mass due to x = Pow (P1, a) * pow* (P2, b) * POW (P3, c) * ...

The approximate number of digits is: num (x) = (a+1) * (b+1) * (c+1) * ...

Derivation:

The approximate definition of P1^A1 is as follows: P1^0, P1^1, P1^2......P1^A1, Total (a1+1); the same as P2^A2 's approximate (a2+1). There are (Pk^ak) an approximate ak+1. Therefore, according to the multiplication principle: N of the number of approximate is (a1+1) (a2+1) (a3+1) ... (ak+1).

So this problem is a direct substitute for this formula.

Test instructions

A number of 64bit is given, and the number of its approximate numbers is obtained;

Code:

1#include <iostream>2#include <stdio.h>3 #definell Long Long4 using namespacestd;5 6 intMainvoid){7 ll N;8      while(SCANF ("%lld", &n) &&N) {9         inta[4]={1,1,1,1};Ten         intb[4]={2,3,5,7}; One          for(intI=0; i<4; i++){ A              while(n%b[i]==0){ -a[i]++; -N/=B[i]; the             } -         } -printf"%d\n", a[0]*a[1]*a[2]*a[3]); -     } +     return 0; -}

hdu1492 (approximate number theorem)

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.