/** * Add power for modifiers */ static int modifier_power(const object_type *obj, int p, bool known) { int i, k = 1, extra_stat_bonus = 0, q; for (i = 0; i < OBJ_MOD_MAX; i++) { if (known || object_this_mod_is_visible(obj, i)) { k = obj->modifiers[i]; extra_stat_bonus += (k * mod_mult(i)); } else continue; if (mod_power(i)) { q = (k * mod_power(i) * mod_slot_mult(i, wield_slot(obj))); p += q; if (q) log_obj(format("Add %d power for %d %s, total is %d\n", q, k, mod_name(i), p)); } } /* Add extra power term if there are a lot of ability bonuses */ if (extra_stat_bonus > 249) { log_obj(format("Inhibiting - Total ability bonus of %d is too high\n", extra_stat_bonus)); p += INHIBIT_POWER; } else if (extra_stat_bonus > 0) { q = ability_power[extra_stat_bonus / 10]; if (!q) return p; p += q; log_obj(format("Add %d power for modifier total of %d, total is %d\n", q, extra_stat_bonus, p)); } return p; }
int mod_power(int t, int k, int m) { if (k == 0) return 1%m; else return k%2 ? ((sqr(mod_power(t, k/2, m))%m)*t)%m : sqr(mod_power(t, k/2, m))%m; }
/** * Returns true if num is composite, false if n may be prime. */ bool brentspollards::witness(int base, cpp_int num, const int count_exponent, const cpp_int count_rest) { cpp_int old_val, current_val; // old_val = base^(2^0 * count_rest) (mod n), on the form old_val = base^(2^i*count_rest) (mod n) where i is 0 old_val = mod_power(base, count_rest, num); //number is probably prime if (old_val == 1 || old_val == num - 1) { return false; } // Check if base^(2^i*count_rest) (mod n) = -1 for some i less than count_exponent for (int i = 1; i <= count_exponent; ++i) { current_val = (old_val * old_val) % num; // current_val = base^(2^i * count_rest) (mod n) if (current_val == num - 1) { return false; } old_val = current_val; // old_val = base^(2^i * count_rest) (mod n) } if (current_val != 1) { return true; } return false; }
int main(void) { int a, b, c, m, res = 0; scanf("%d%d%d%d", &a, &b, &c, &m); res = max(res, mod_power(a, power(b, c), m)); res = max(res, mod_power(a, power(c, b), m)); res = max(res, mod_power(b, power(a, c), m)); res = max(res, mod_power(b, power(c, a), m)); res = max(res, mod_power(c, power(a, b), m)); res = max(res, mod_power(c, power(b, a), m)); printf("%d\n", res); return 0; }
/** * Returns true if n is composite, false if n may be prime. */ bool pollards::witness(int base, cpp_int num, const int count_exponent, const cpp_int count_rest) { cpp_int old_val, current_val; old_val = mod_power(base, count_rest, num); // old_val = base^(2^0 * count_rest) (mod n) if (old_val == 1 || old_val == num - 1) { return false; } for (int i = 1; i <= count_exponent; ++i) { current_val = (old_val * old_val) % num; // current_val = base^(2^i * count_rest) (mod n) if (current_val == num - 1) { return false; } old_val = current_val; // old_val = base^(2^i * count_rest) (mod n) } if (current_val != 1) { return true; } return false; }