0
Prime numbers
Hi I have a basic code in C++ #include <iostream> using namespace std; int main(){ int n,i,x; cin>>n; do{cin>>x; } while(x<=n); system("pause"); return 0; } I want to give me the biggest number in case of how many prime do they have and take the biggest number as output. If there was a case with two number with the same answer like 12 and 18 which they have 2 prime number, it should show the first input that I gave in this case 12. I don't know how to write a code about the amount of numbers and which one is the biggest or the first input. The output must be like this 5 12 18 4 17 20 12
3 Respostas
0
I didn't understand your question exactly but I think this code
https://code.sololearn.com/cmI2ruUSgZbc/#cpp
can help you.
+ 1
Thanks a lot SoloProg.
0
Exercise series three:
Get from integer input
And count that number again
Count the number of divisors of each number in order, and finally the number that has the most divisors of the first will be considered (if two numbers are equal to the number of divisors of the first, the first number will be considered)
Finally, print the number with the sum of its digits.
Example:
(The first input number is 5, so we get another 5)
5
12
18
4
17
20
Divisor against the number 12:
1,2,3,4,6,12
Which is only the first 2.3 numbers
So the number 12 has two divisors against the first.
We continue until the end and choose the number that is most divisible by the first.
Number of divisors of the first opposites of each:
12 -> 2
18 -> 2
4 -> 1
17 -> 1
20 -> 2
In the example above, 3 is equal to the number of divisors of the first, which we must choose the first number, ie the number 12
Finally, we calculate and print the number 12 with the sum of its digits, ie 3 (2 + 1).