#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <unistd.h>
#define ullong unsigned long long
int
check(ullong value,
int
try_count) {
int
buf1[10000];
int
buf2[10000];
int
buf3[20000];
int
buf4[20000];
unsigned
int
v[] = {2, 4, 5, 6, 7, 8, 13};
for
(
int
_ = 0; _ < try_count; _++) {
for
(
int
i = 0; i < 10000; i++) {
int
_v = v[
rand
() % 7];
buf1[i] = _v;
if
(i) {
buf2[i] =
rand
() % _v;
}
else
{
buf2[i] =
rand
() % (_v - 1) + 1;
}
}
for
(
int
i = 0; i < 20000; i++) {
buf3[i] = v[
rand
() % 7];
}
int
i12 = 0;
int
i34 = 0;
ullong tmpv = 0;
while
(i12 < 10000 || tmpv > 0) {
if
(i34 >= 20000) {
assert
(0 ||
"1"
);
return
1;
}
ullong tmpv_bak = tmpv;
if
(i12 >= 10000) {
tmpv = tmpv / buf3[i34];
buf4[i34] = tmpv_bak % buf3[i34];
i34 += 1;
}
else
{
tmpv = buf1[i12] * tmpv + buf2[i12];
if
(tmpv_bak / buf3[i34] * tmpv >= value) {
tmpv = tmpv_bak / buf3[i34];
buf4[i34] = tmpv_bak % buf3[i34];
i34 += 1;
}
else
{
i12 += 1;
}
}
}
i12 = 10000 - 1;
i34 -= 1;
tmpv = 0;
while
(i34 >= 0 || tmpv > 0) {
if
(i12 < 0) {
assert
(0 ||
"2"
);
return
1;
}
ullong tmpv_bak = tmpv;
if
(i34 < 0) {
tmpv = tmpv / buf1[i12];
if
(tmpv_bak % buf1[i12] != buf2[i12]) {
return
1;
}
i12 -= 1;
}
else
{
tmpv = buf3[i34] * tmpv + buf4[i34];
if
(tmpv_bak / buf1[i12] * tmpv >= value) {
tmpv = tmpv_bak / buf1[i12];
if
(tmpv_bak % buf1[i12] != buf2[i12]) {
return
1;
}
i12 -= 1;
}
else
{
i34 -= 1;
}
}
}
}
return
0;
}
int
main() {
setbuf
(stdout, NULL);
int
try_count = 100;
srand
(
time
(NULL));
#define PROCESS_COUNT 16
#define INIT_VALUE (1898762303l)
#define FINI_VALUE (1898787472l)
#define TASK_COUNT ((FINI_VALUE - INIT_VALUE) / PROCESS_COUNT)
#define LOG_TOTAL (100)
#define COUNT_TO_LOG (TASK_COUNT / LOG_TOTAL)
for
(
int
j = 0; j < PROCESS_COUNT; j++) {
if
(!fork()) {
int
logged_count = 0;
int
counting = COUNT_TO_LOG;
printf
(
"process %d started (0x%lx - 0x%lx).\n"
, j, INIT_VALUE + j * TASK_COUNT, INIT_VALUE + j * TASK_COUNT + TASK_COUNT);
for
(ullong i = INIT_VALUE + j * TASK_COUNT; i < INIT_VALUE + j * TASK_COUNT + TASK_COUNT; i++) {
if
(!check(i, try_count) && !check(i, 10000)) {
printf
(
"found: %lld\n"
, i);
}
else
{
}
counting--;
if
(counting <= 0) {
counting = COUNT_TO_LOG;
logged_count += 1;
printf
(
"process %d: %d / %d\n"
, j, logged_count, LOG_TOTAL);
}
}
printf
(
"process %d done.\n"
, j);
exit
(0);
}
}
getchar
();
return
0;
}