Permuted multiples

Problem 52 Description It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order. Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits. Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def solution(): for i in range(1, 1000000): a = str(i * 2) b = str(i * 3) c = str(i * 4) d = str(i * 5) e = str(i * 6) if ( sorted(a) == sorted(b) and sorted(a) == sorted(c) and sorted(a) == sorted(d) and sorted(a) == sorted(e) ): return i Summary It limit the number range to one billion.

位运算

描述 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include <stdio.h> #include "bit_ops.h" /* Returns the Nth bit of X. Assumes 0 <= N <= 31. */ unsigned get_bit(unsigned x, unsigned n) { return (x >> n) & 1; /* UPDATE WITH THE CORRECT RETURN VALUE*/ } /* Set the

Number spiral diagonals

Problem 28 Description Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 It can be verified that the sum of the numbers on the diagonals is 101. What is the sum

Largest product in a grid

Problem 11 Description In the 20×20 grid below, four numbers along a diagonal line have been marked in red. The product of these numbers is 26 × 63 × 78 × 14 = 1788696. What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? Solution 1 2 3 4

Sub-string divisibility

Problem 43 Description 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 1st digit, $d_2$ be the 2nd digit, and so on. In this way, we note the following: $d_2d_3d_4=406$ is divisible by 2 $d_3d_4d_5=063$ is divisible by 3