POJ2603
来源:互联网 发布:阿里云学生服务器购买 编辑:程序博客网 时间:2024/04/28 17:14
Brave balloonists
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4721 Accepted: 2013
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.
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
1261311111
Sample Output
9思想:本题输入十个数,求出这十个数相乘最后所得数的因子个数,再对因子个数取个位,p1p2…pr为素数, 因子个数为(1+a1)*(1+a2)*(1+a3)*...*(1+an)对于每个ai,有ai+1种取法。解题代码:#include <iostream>#include <cstdio>#include <cmath>#include <cstring>using namespace std;#define N 10005bool ispri[N];int pri[N];int get_pri[N];void getpri(){ memset(ispri, true, sizeof(ispri)); ispri[0] = ispri[1] = 0; int t = 0; for(int i = 2 ; i <= N ; i ++) { if(ispri[i]) { pri[++t] = i; for(int j = i * i; j <= N ; j += i) ispri[j] = false; } } pri[0] = 0;}void solve(int n){ for(int i = 1; pri[i] * pri[i] < n ; i ++) { if(n % pri[i] == 0) { while(n % pri[i] == 0) { get_pri[pri[i]]++; n /= pri[i]; } } } if(n > 1) get_pri[n]++;}int main(){//freopen("in.txt","r",stdin); getpri(); int a; for(int i = 0; i < 10; i ++) { scanf("%d",&a); solve(a); } int ans = 1; for(int i = 1 ; i < N ; i ++) { if(get_pri[i]) ans = ans * (get_pri[i] + 1) % 10; } printf("%d\n",ans); }
0 0
- POJ2603
- POJ2603 fundemental theorm arithmetic&& the num of divisor
- 第一次的go访问七牛云存储的sdk
- iscsi问题锦集
- windows程序扫雷程序设计
- VM虚拟机中Linux扩展磁盘空间的方法
- HDU2795 Billboard 【线段树】+【单点更新】
- POJ2603
- Java多线程编程入门
- 资源
- 线性回归-实践篇
- Windows如何在cmd命令行中查看、修改、删除与添加、设置环境变量
- nyoj290动物统计加强版(字典树)
- 设计模式之十五:访问者模式(Visitor Pattern)
- log4j&&slf4j配置详解
- iOS多线程编程之NSOperation和NSOperationQueue的使用