如何找到“数字乘积”的因子数?

编程入门 行业动态 更新时间:2024-10-26 12:26:07
本文介绍了如何找到“数字乘积”的因子数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正试图找出大数乘积的因数。

I m trying to find number of factors of product of big numbers.

问题陈述是:假设您得到N个数字(假设N = 10 ),每个数字< =1000000。如何查找此类数字乘积的数量。

The problem statement is this : Suppose you are given N numbers(let say N = 10), each number <= 1000000. How to find the number of factors of the product of such numbers.

请问有人可以提供一种有效的算法

Can someone please provide an efficient algorithm for doing this.

示例:

1)N = 3,数字为3、5、7

1) N = 3 and Numbers are 3, 5, 7

Ans = 8(1、3、5、7、15、21、35、105)

Ans = 8 (1, 3, 5, 7, 15, 21, 35, 105)

2) N = 2,数字为5、5

2) N = 2 and Numbers are 5, 5

Ans = 3(1、5和25)

Ans = 3 (1, 5 and 25)

推荐答案

问题的编辑在这里

discuss.codechef/questions/15943/numfact-editorial

int total = 0, N = 0, Number; scanf ("%d", &total); while (total--) { scanf ("%d", &N); map<int, int> Counter; for (int i = 0; i < N; i++) { scanf ("%d", &Number); for (int j = 2; j * j <= Number; j++) { while (Number % j == 0) { Counter[j]++; Number /= j; } } if (Number > 1) Counter[Number]++; } int Answer = 1; for (map<int, int>::iterator it = Counter.begin(); it != Counter.end(); it++) Answer *= (it->second + 1); printf ("%d\n", Answer); }

已被接受。

样本输入和输出:

7 3 3 5 7 3 2 4 6 2 5 5 10 2 2 2 2 2 2 2 2 2 2 1 100 10 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 8 10 3 11 9 1681 3721

更多推荐

如何找到“数字乘积”的因子数?

本文发布于:2023-11-30 12:19:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649922.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:乘积   因子   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!