#include using namespace std; #define ull unsigned long long int // 111111 // 123456789012345 const ull N = 1000000000000000; set chk; ull c, d, b, m; ull digitSum(ull x){ ull sum = 0; while (x > 0){ sum += x % b; x /= b; } return sum; } int main(int argc, char **argv){ FILE *inf = fopen(argv[1], "r"); FILE *ans = fopen(argv[2], "r"); FILE *ouf = fopen(argv[3], "r"); fscanf(inf, "%llu %llu %llu %llu", &c, &d, &b, &m); ull sum = 0; for (ull i = 1; i <= m; i++){ ull x; assert( fscanf(ouf, "%llu", &x) == 1 ); assert(1 <= x && x <= N); assert(chk.count(x) == 0); chk.insert(x); x = c*x + d; if (i == 1){ sum = digitSum(x); } assert( sum == digitSum(x) ); } ull x; assert( fscanf(ouf, "%llu", &x) != 1 ); fclose(inf); fclose(ans); fclose(ouf); return 0; }