用了一个蠢办法,反正过了。懒得弄了。
/*
ID :
LANG: C++11
TASK: runround
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
char c[32] = {};
bool b[32] = {};
bool bR[10] = {};
inline bool test(int m){
memset(c, 0, sizeof(c));
memset(b, 0, sizeof(b));
memset(bR, 0, sizeof(bR));
sprintf(c, "%d", m);
string s(c);
int l = s.length();
int count = 1;
int p = s[0] - '0';
b[0] = true;
bR[s[0] - '0'] = true;
if (p >= l)
p = p % l;
while (p != 0){
if (b[p] == true || bR[s[p] - '0'] == true)
return false;
b[p] = true;
bR[s[p] - '0'] = true;
p = p + s[p] - '0';
p %= l;
count ++;
}
if (count < l)
return false;
return true;
}
int main()
{
freopen("runround.in", "r", stdin);
freopen("runround.out", "w", stdout);
unsigned long M;
cin >> M;
int m = M + 1;
while (!test(m)){
m++;
}
cout << m << endl;
return 0;
}