欧拉计划 Project Euler 52(重排的倍数) 题解
欧拉计划 Problem 52 题解
- 题干
- 思路
- code
题干
思路
直接暴力即可,可知答案是142857
code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool check(string s1, string s2) {
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
return s1 == s2;
}
void solve() {
for (int i = 10; i <= 1000000; ++i) {
string a = to_string(i); // 142857
string b = to_string(i * 2);
string c = to_string(i * 3);
string d = to_string(i * 4);
string e = to_string(i * 5);
string f = to_string(i * 6);
if (check(a, b) && check(a, c) && check(a, d) && check(a, e) && check(a, f)) {
cout << i << "\n";
break;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1; // cin >> tt;
while (tt--) {
solve();
}
return 0;
}