给定数字的不同素数的数量

编程入门 行业动态 更新时间:2024-10-24 12:27:35
本文介绍了给定数字的不同素数的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想找到给定数字的不同素数的数量,我将数组传递给函数,然后将数组的所有元素相乘以生成数字,我得到一些测试用例的BUS ERROR 我尝试过:

I want to find the number of distinct prime number of a given number, I am passing a array to the function and then multiplying all the elements of the array to generate the number, I am getting BUS ERROR for some test cases What I have tried:

int Solution::solve(vector<int> &A) { long long int mul = 1; for(int i=0;(i<A.size()-1);i++) { mul = mul*A[i]; } int new1 = mul; int arr[new1 + 1]; memset(arr, 0, sizeof(arr)); for (int i = 2; i * i <= new1; i++) { if (!arr[i]) { for (int j = 2 * i; j <= new1; j += i) { arr[j]++; } } arr[i] = 1; } return *max_element(arr, arr+new1); }

推荐答案

这段代码很奇怪: This code is weird: for(int i=0;(i<A.size()-1);i++) { mul = mul*A[i]; }

因为它乘以所有向量但最后一个

because it multiply all number of the vector but the last one.

Quote:

我想找到给定数字的不同素数的数量

I want to find the number of distinct prime number of a given number

你可以定义这个吗? 因为我理解它,它不是你的代码,它甚至不是很接近。 据我所知,你的代码返回 mul 以下的所有素数列表。 完成代码以便运行。 显示一个输入示例,提供错误消息。

Can you define this ? Because as I understand it, it is not what is doing your code, it- is not even close. As I understand it, your code return a list of all prime numbers below mul. Complete your code so it can be run. Show an input example that give you the error message.

更多推荐

给定数字的不同素数的数量

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

发布评论

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

>www.elefans.com

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