Posts

Showing posts from 2020

Weird numbers | Rosetta Code | #25

URL to the problem page:  http://rosettacode.org/wiki/Weird_numbers In number theory, a weird number is a natural number that is abundant but not semiperfect (and therefore not perfect either). In other words, the sum of the proper divisors of the number (divisors including 1 but not itself) is greater than the number itself (the number is abundant ), but no subset of those divisors sums to the number itself (the number is not semiperfect ). For example: 12 is not a weird number.     It is abundant; its proper divisors 1, 2, 3, 4, 6 sum to 16 (which is > 12),     but it is semiperfect, eg 6 + 4 + 2 == 12 . 70 is a weird number.     It is abundant; its proper divisors 1, 2, 5, 7, 10, 14, 35 sum to 74 (which is > 70),     and there is no subset of proper divisors that sum to 70 . Find and display, here on this page, the first 25 weird numbers. #include   <iostream> using   namespace ...

Fermat numbers | Rosetta Code | #24

URL to the problem page:  http://rosettacode.org/wiki/Fermat_numbers In mathematics, a Fermat number, named after Pierre de Fermat who first studied them , is a positive integer of the form F n  = 2 2^ n  + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-random number generation, and are often linked to other number theoric fields. As of this writing, (mid 2019), there are only five known prime Fermat numbers, the first five ( F 0  through F 4 ). Only the first twelve Fermat numbers have been completely factored, though many have been partially factored. Find and display here, on this page, the first 10 Fermat numbers - F 0  through F 9 . #include   <iostream> using   namespace   std ; int   power ( int   a ,  int   b ) {      int  re...

Smith numbers | Rosetta Code | #23

URL to the problem page:  https://rosettacode.org/wiki/Smith_numbers Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as joke numbers. Example Using the number 166 Find the prime factors of 166 which are: 2 x 83 Then, take those two prime factors and sum all their decimal digits: 2 + 8 + 3 which is 13 Then, take the decimal digits of 166 and add their decimal digits: 1 + 6 + 6 which is 13 Therefore, the number 166 is a Smith number. Write a program to find all Smith numbers below 10000. #include   <iostream> using   namespace   std ; int  n =  0 ,  factors [ 512 ] = {  0  }, multiply =  1 , thenumber =  0 ; int   power ...

Zumkeller numbers | Rosetta Code | #22

URL to the problem page:  http://rosettacode.org/wiki/Zumkeller_numbers Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that the two partition sums are equal. E.G.  6 is a Zumkeller number; The divisors {1 2 3 6} can be partitioned into two groups {1 2 3} and {6} that both sum to 6. 10 is not a Zumkeller number; The divisors {1 2 5 10} can not be partitioned into two groups in any way that will both sum to the same value. 12 is a Zumkeller number; The divisors {1 2 3 4 6 12} can be partitioned into two groups {1 3 4 6} and {2 12} that both sum to 14. Even Zumkeller numbers are common; odd Zumkeller numbers are much less so. For values below 10^6, there is at least one Zumkeller number in every...

Magnanimous numbers | Rosetta Code | #21

URL to the problem page:  http://rosettacode.org/wiki/Magnanimous_numbers A magnanimous number is an integer where there is no place in the number where a + (plus sign) could be added between any two digits to give a non-prime sum. E.G. 6425 is a magnanimous number. 6 + 425 == 431 which is prime; 64 + 25 == 89 which is prime; 642 + 5 == 647 which is prime. 3538 is not a magnanimous number. 3 + 538 == 541 which is prime; 35 + 38 == 73 which is prime; but 353 + 8 == 361 which is not prime. Traditionally the single digit numbers 0 through 9 are included as magnanimous numbers as there is no place in the number where you can add a plus between two digits at all. (Kind of weaselly but there you are...) Except for the actual value 0, leading zeros are not permitted. Internal zeros are fine though, 1001 -> 1 + 001 (prime), 10 + 01 (prime) 100 + 1 (prime). There are only 571 known magnanimous numbers. It is strongly suspected, though not rigorously proved, th...
My photo
Ercan Tomac
instagram.com/ercantomac