POJ 2603 Brave balloonists

Brave balloonists
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4546   Accepted: 1924

Description

Ten mathematicians are flying on a balloon over the Pacific ocean. When they are crossing the equator they decide to celebrate this event and open a bottle of champagne. Unfortunately, the cork makes a hole in the balloon. Hydrogen is leaking out and the balloon is descending now. Soon it will fall into the ocean and all the balloonists will be eaten by hungry sharks.
But not everything is lost yet. One of the balloonists can sacrifice himself jumping out, so that his friends would live a little longer. Only one problem still exists ¾ who is the one to get out. There is a fair way to solve this problem. First, each of them writes an integer ai not less than 1 and not more than 10000. Then they calculate the magic number N that is the number of positive integer divisors of the product a1*a2*...*a10. For example, the number of positive integer divisors of 6 is 4 (they are 1,2,3,6). The hero (a mathematician who will be thrown out) is determined according to the last digit of N. Your task is to find this digit.

Input

Input file contains ten numbers separated by a space.

Output

Output file should consist of a single digit from 0 to 9 - the last digit of N.

Sample Input

1
2
6
1
3
1
1
1
1
1

Sample Output

9

Source

求10个数相乘 约数个数%10 

若正整数n可分解为(p1^a1)*(p2^a2)*…*(pk^ak)
其中pi为两两不同的素数,ai为对应指数
n的约数个数为(1+a1)*(1+a2)*….*(1+ak)

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <string.h>
using namespace std;
bool hash[10000];
bool is_p(int &n)
{
    int i,m=sqrt(double(n));
    for(i=3;i<=m;i+=2)
     if(n%i==0)
       return false;
    return true;
}
int rc[1300],l;
void set()
{
     int i,j;
    for(i=4;i<10000;i+=2)
      hash[i]=1;
    for(i=3;i<10000;i+=2)
       if(is_p(i))
         for(j=i+i;j<10000;j+=i)
           hash[j]=1;
    j=0;
    for(i=2;i<10000;i++)
     if(!hash[i])
      rc[j++]=i;
    l=j;
}
int p[100],q[100];
int main()
{
    set();
    memset(hash,0,sizeof(hash));
    int i;
    int n;
    int l=0,k,j;
    for(i=0;i<10;i++)
    {
        scanf("%d",&n);
        k=0;
        while(n!=1)
        {
            while(n%rc[k]==0)
            {
                if(!hash[rc[k]])
                {
                    p[l]=rc[k];
                    q[l]=2;
                    hash[rc[k]]=1;
                    l++;
                }
                else
                {for(j=0;j<l;j++)
                    {
                      if(p[j]==rc[k])
                        {q[j]++;break;}
                    }
                }
             n=n/rc[k];
            }
          k++;
        }
    }
    int s=1;
    for(i=0;i<l;i++)
      {
         s=(s*q[i])%10;
      }
    printf("%d\n",s);
    return 0;
}

原文地址:https://www.cnblogs.com/372465774y/p/2602644.html