Quantcast
Channel: YGC » c++
Viewing all articles
Browse latest Browse all 18

project euler -- problem 52

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

1/7-6/7的数字是一样的,这是小学水平啊。

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
28
29
#include<set>
#include<iostream>
using namespace std;
 
set<int> get_digits(int n);
 
int main() {
  int x = 1;
  while(x) {
    if(get_digits(2*x) == get_digits(3*x) &&
       get_digits(2*x) == get_digits(4*x) &&
       get_digits(2*x) == get_digits(5*x) &&
       get_digits(2*x) == get_digits(6*x) ) {
      cout << x << endl;
      break;
    }
    x++;
  }
  return 0;
}
 
set<int> get_digits(int n) {
  set<int> res;
  while (n) {
    res.insert(n % 10);
    n /= 10;
  }
  return res;
}

Related Posts


Viewing all articles
Browse latest Browse all 18

Trending Articles