Nyoj 476 who is the hero (unique factor decomposition theorem)

Source: Internet
Author: User

Title Description

http://acm.nyist.net/JudgeOnline/problem.php?pid=476

10 Mathematicians (No. 0-9) flew over the Pacific Ocean by balloon. When crossing the equator, they decided to celebrate the feat. So they opened a bottle of champagne. Unfortunate

, the Cork has a hole in the balloon, the hydrogen leaks, the balloon starts to fall, and it's going to fall into the sea, and everyone is going to be eaten by sharks.


But there are chance--if one of them sacrifices himself to jump, his friends will live a little longer. But there is still a problem--who

Jump down? So they think of a very fair way to solve this problem--first, each person writes an integer AI;

Figure out the number of a1xa2xa3xa4x......xa10 of the product of N. For example, 6 of the approximate 4 (1, 2, 3, 6), then n is 4. The Sacrifice from

The hero of his own will be determined by the number of bits in N (the number of single digits of n is to jump). Your task is to find out N.

Input
T (t<=10) group test data.
10 integer ai (1≤ai≤10000).
Output
Single digit of n
Sample input
11 2 6 1 3 1 1 1 1 1
Sample output
9

Topic Analysis:

The only factor decomposition problem, for any number n, can be expressed as: n=p[0]^a[0]*... *p[i]^a[i]*......*p[n]^a[n], where P[i] is a prime, a[i] is an integer > 0, while the sum of the approximate number of n is, sum= (a[0]+1) *.....* (a[i]+1)* ... (a[n]+1).


AC Code:

/** * @xiaoran * unique prime factor decomposition, the approximate number of n is pi (a[i]+1) *res= (a[0]+1) * (a[1]+1) *...* (a[n]+1), where a[i] are prime numbers */#include <iostream> #include <cstdio> #include <map> #include <cstring> #include <string> #include <algorithm > #include <queue> #include <vector> #include <stack> #include <cstdlib> #include <cctype    > #include <cmath> #define LL long longusing namespace Std;int a[10000];int main () {int t,n;    cin>>t;        while (t--) {int res=1,x,k,m=0;        memset (A,0,sizeof (a));            for (int i=0;i<10;i++) {cin>>n;            if (m<n) m=n;//record maximum value x=n;                    for (int i=2;i<=n;i++) {while (x%i==0) {//record the number of times each element factor appears a[i]++;                X/=i;            } if (x==1) break;        }} for (int i=2;i<=m;i++) {res*= (a[i]+1);    } cout<<res%10<<endl; }return 0;}



Nyoj 476 who is the hero (unique factor decomposition 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.