按着作者思路,我直接穷举了所有有生成元的数字。代码如下:
#include <stdio.h>
#include "stdafx.h"
#include <iostream>
#include<time.h>
#include<iomanip>
#include<string.h>
#define maxn 1000
using std::cin;
using std::cout;
int main() {
int i, m=0;
for (i = 1; i <= 100000; i++) {
if (1 <= i && 1 < 10)
m = i + i;
if (10 <= i && 1 < 100)
m = i % 10 + i / 10 + i;
if (100 <= i && 1 < 1000)
m = i % 100 / 10 + i % 100 % 10 + i / 100 + i;
if (1000 <= i && 1 < 10000)
m = i % 1000 % 100 % 10 + i % 1000 % 100 / 10 + i % 1000 / 100 + i / 1000 + i;
if (10000 <= i && 1 < 100000)
m = i % 10000 % 1000 % 100 % 10 + i % 10000 % 1000 % 100 / 10 + i % 10000 % 1000 / 100 + i % 10000 / 1000 + i / 100000 + i;
cout << m << std::endl;
}
}