|
发表于 2016-8-22 13:19:12
|
显示全部楼层
- #include <iostream>
- #include <climits>
- #include <algorithm>
- #include <vector>
- bool interesting(unsigned long long x); //判断数字是否符合要求
- int main() {
- std::vector<unsigned long long> arr;
- for (int i = 2; i < 180; i++) {
- unsigned long long temp = i;
- while (temp < ULLONG_MAX / i) {
- if (temp > 10){
- arr.push_back(temp);
- }
- temp *= i;
- }
- }
- sort(arr.begin(), arr.end());
- std::vector<unsigned long long>::iterator pos = unique(arr.begin(), arr.end());
- arr.erase(pos, arr.end()); //除去重复的数字
- int k = 1;
- for (std::vector<unsigned long long>::iterator itr = arr.begin(); itr != arr.end(); itr++){
- if (interesting(*itr)) {
- std::cout << "a[" << k << "] = " << *itr << std::endl;
- k++;
- }
-
- }
- system("PAUSE");
- return 0;
- }
- bool interesting(unsigned long long x) {
- unsigned int sum = 0;
- unsigned long long temp = x;
- while (temp != 0){
- sum += temp % 10;
- temp /= 10;
- }
- if (sum == 1) {
- return false;
- }
- while (x != 1) {
- if (x % sum != 0){
- return false;
- }
- x /= sum;
- }
- return true;
- }
复制代码 |
|