数组元素的频率是否为质数?

2023年 8月 29日 53.8k 0

数组元素的频率是否为质数?

Suppose we have one array. we have to count how many of the elements present in the array prime number of times. So if the array is {1, 2, 2, 0, 1, 5, 2, 5, 0, 0, 1, 1}, then 1 is present 4 times, 2 is present 3 times, 0 is present 3 times, and 5 is present 2 times. So there are three elements {2, 0, 5} that have occurred prime number of times. So the count will be 3.

Algorithm

countPrimeOccurrence(arr, n)

Begin
count := 0
define map with int type key and int type value
for each element e in arr, do
increase map.key(arr).value
done
for each key check whether the value corresponding the value is prime or not, if prime, then increase count.
return count
End

登录后复制

Example

#include
#include
using namespace std;
bool isPrime(int n){
for(int i = 2; i

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论