(OBJC)
int main(int argc, const char * argv[]) {
// Search positive integers for solutions, up to 10^20.
for (int length = 1; length < 20; ++length) {
for (int a = 0; a <= 9; ++a) {
int b = 9 - a;
// Test number abababab... with length 'length'
int a_mod_11 = (a * ((length + 1) / 2)) % 11;
int b_mod_11 = (b * ((length ) / 2)) % 11;
int a_add = (b_mod_11 - a_mod_11 + 11) % 11;
if (a + a_add == 10) {
uint64_t num = 0;
uint64_t dec = 1;
for (int d = 0; d < length; ++d) {
num += ((d & 1) ? b : a) * dec;
dec *= 10;
}
NSLog(@"Found solution: %llu", num);
}
}
}
return 0;
}
|