Posts

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...

Esthetic numbers | Rosetta Code | #20

URL to the problem page:  http://rosettacode.org/wiki/Esthetic_numbers An esthetic number is a positive integer where every adjacent digit differs from its neighbour by 1. E.G. 12 is an esthetic number. One and two differ by 1. 5654 is an esthetic number. Each digit is exactly 1 away from its neighbour. 890 is not an esthetic number. Nine and zero differ by 9. These examples are nominally in base 10 but the concept extends easily to numbers in other bases. Traditionally, single digit numbers are included in esthetic numbers; zero may or may not be. For our purposes, for this task, do not include zero (0) as an esthetic number. Do not include numbers with leading zeros. Esthetic numbers are also sometimes referred to as stepping numbers . Find and display, here on this page, the base 10 esthetic numbers with a magnitude between 1000 and 9999 . #include   <iostream> using   namespace   std ; int   finddigits ( int   a )...

Palindromic gapful numbers | Rosetta Code | #19

URL to the problem page:  http://rosettacode.org/wiki/Palindromic_gapful_numbers Numbers that are (evenly) divisible by the number formed by the first and last digit are known as gapful numbers . Evenly divisible means divisible with no remainder. All one─ and two─digit numbers have this property and are trivially excluded. Only numbers ≥ 100 will be considered for this Rosetta Code task.       Example 1037 is a gapful number because it is evenly divisible by the number 17 which is formed by the first and last decimal digits of 1 03 7 . A palindromic number, when the number is reversed, is the same as the original number. Show (nine sets) the first 20 palindromic gapful numbers that end with: the digit 1 the digit 2 the digit 3 ··· ··· the digit 9 #include   <iostream> using   namespace   std ; int   finddigits ( int   a ) {      int  cnt =  1 ;    ...

Hamming numbers | Rosetta Code | #18

URL to the problem page:  https://rosettacode.org/wiki/Hamming_numbers Hamming numbers are numbers of the form H = 2 i  × 3 j  × 5 k where i, j, k ≥ 0 Hamming numbers are also known as ugly numbers and also 5-smooth numbers (numbers whose prime divisors are less or equal to 5). Show the first twenty Hamming numbers. Show the 1691 st  Hamming number (the last one below 2 3 1 ). #include   <iostream> using   namespace   std ; long   long   int   power ( int   a ,  int   b ) {      long   long   int  result =  1 ;      for  ( int  i =  0 ; i < b; i++) {         result *= a;     }      return  result; } int   main () {      int  cnt, a =  0 ,...

Happy numbers | Rosetta Code | #17

URL to the problem page:  http://rosettacode.org/wiki/Happy_numbers A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers. Find and print the first 8 happy numbers. #include   <iostream> using   namespace   std ; int   power ( int   a ,  int   b ) {      int  result =  1 ;      for  ( int  i =  0 ; i < b; i++) {         result *= a;     }      return  result; } int   main () {  ...

Sub-string divisibility | Project Euler | Problem #43

URL to the problem page:  https://projecteuler.net/problem=43 The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property. Let d 1  be the 1 st  digit, d 2  be the 2 n d  digit, and so on. In this way, we note the following: d 2 d 3 d 4 =406 is divisible by 2 d 3 d 4 d 5 =063 is divisible by 3 d 4 d 5 d 6 =635 is divisible by 5 d 5 d 6 d 7 =357 is divisible by 7 d 6 d 7 d 8 =572 is divisible by 11 d 7 d 8 d9=728 is divisible by 13 d 8 d 9 d 1 0 =289 is divisible by 17 Find the sum of all 0 to 9 pandigital numbers with this property. #include   <iostream> using   namespace   std ; long   long   power ( long   long   a ,  long   long   b ) {      long   long  result =  1 ;      for  ( long ...
My photo
Ercan Tomac
instagram.com/ercantomac