描述
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.
输入
The first line of input contains a number c(0<c<=1000) giving the number of cases that follow. each case contains ten numbers separated by a space.
输出
Output each case of a single digit from 0 to 9 - the last digit of N
样例输入
1
1
2
6
1
3
1
1
1
1
1样例输出
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.
输入
The first line of input contains a number c(0<c<=1000) giving the number of cases that follow. each case contains ten numbers separated by a space.
输出
Output each case of a single digit from 0 to 9 - the last digit of N
样例输入
1
1
2
6
1
3
1
1
1
1
1样例输出
9
http://59.69.128.200/JudgeOnline/problem.php?pid=416
思路:这道题就是先求出一个数的所有约数个数。如果按一般的思想,可能需要尝试n次,现在我介绍的方法就是,首先求出该数能分解成素因子的个数,假设一个数分解成2因子的个数为m,那么求最后的因子时对2有m+1种取法,最后求得所有因子个数就为所求因子数加1,相乘。
代码:
#include<stdio.h> #include<string.h> #define max 10000 int a[max]; int main() { int N; scanf("%d",&N); while(N--) { memset(a,0,sizeof(a)); int i,j; for( i=0;i<10;i++) { int n; scanf("%d",&n); if(n==1) continue ; for(j=2;n!=1;) { if(n%j==0) { a[j]++; n=n/j; } else j++; } } int sum=1; for(i=2;i<max;i++) if(a[i]!=0) sum=(sum*(a[i]+1)); printf("%d\n",sum%10); } return 0; }