#include #define INIT_VALUE 0 #define ARRAY_SIZE 500 #define EXIT_SUCCESS 0 int a = INIT_VALUE, b = INIT_VALUE, k = INIT_VALUE, c = INIT_VALUE; char result[ARRAY_SIZE]; void parse_input() { scanf("%d %d %d %d", &a, &b, &k, &c); } int parse_char(char x) { switch (x) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; } return -1; } char parse_int(int i) { switch (i) { case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4'; case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9'; } return 'x'; } void _memset(char* array, char value, int reps) { int i; for (i = 0; i < reps; i++) { array[i] = value; } } void multiply_string(int n) { int number, temp, calc, temp2 = 0, i, j, multiplicator; char sum[ARRAY_SIZE]; _memset(sum, '0', ARRAY_SIZE); if (n >= 10) { j = 0; while (n > 0) { multiplicator = n % 10; if (multiplicator == 0) { n = (n / 10); j++; continue; } temp2 = 0; for (i = ARRAY_SIZE - 1; i >= 0; i--) { // NACITANIE CISLICE number = parse_char(result[i]); // VYPOCITAM SUCIN calc = number * multiplicator; // VYPOCITAM ZVYSOK temp = calc >= 10 ? (calc - (calc % 10)) / 10 : 0; // ZOBERIEM LEN JEDNOTKY calc = calc % 10; //NASOBKY DESIATOK if (j > 0) { if ((parse_char(sum[i - j]) + calc + temp2) >= 10) { temp = ((parse_char(sum[i - j]) + calc + temp2) - ((parse_char(sum[i - j]) + calc + temp2) % 10)) / 10; sum[i - j] = parse_int((parse_char(sum[i - j]) + calc + temp2) % 10); } else sum[i - j] = parse_int(parse_char(sum[i - j]) + calc + temp2); } else { if ((calc + temp2) >= 10) { temp = ((calc + temp2) - ((calc + temp2) % 10)) / 10; sum[i] = parse_int((calc + temp2) % 10); } else sum[i] = parse_int(calc + temp2); } temp2 = temp; } n = (n - multiplicator) / 10; j++; } for (i = 0; i < ARRAY_SIZE; i++) result[i] = sum[i]; return; } for (i = ARRAY_SIZE - 1; i >= 0; i--) { number = parse_char(result[i]); calc = number * n; temp = calc >= 10 ? (calc - (calc % 10)) / 10 : 0; calc = calc % 10; result[i] = parse_int(calc + temp2); temp2 = temp; } } void print_string_number() { int i; for (i = 0; i < ARRAY_SIZE; i++) { if (result[i] != '0') { printf("%s", result + i); break; } } } void two_pow(int n) { int i; for (i = 0; i < n; i++) multiply_string(2); multiply_string(k); } int main(int argc, char** argv) { parse_input(); _memset(result, '0', ARRAY_SIZE); result[ARRAY_SIZE - 1] = '1'; two_pow(k - 1); if (c == a || c == b) print_string_number(); else puts("0"); return EXIT_SUCCESS; }