POJ 2603 Brave balloonists
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4546 | Accepted: 1924 |
Description
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
Output
Sample Input
1 2 6 1 3 1 1 1 1 1
Sample Output
9
Source
求10个数相乘 约数个数%10
其中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;
}