#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
static unsigned fast_mod(uint64_t x, unsigned m) {
    // Optimized mod for Codeforces 32-bit machines.
    // x must be less than 2^32 * m for this to work, so that x / m fits in an unsigned 32-bit int.
    unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
    unsigned quot, rem;
    asm("divl %4\n"
        : "=a" (quot), "=d" (rem)
        : "d" (x_high), "a" (x_low), "r" (m));
    return rem;
}

class Timer {
    std::chrono::time_point<std::chrono::steady_clock> timePoint;
    size_t value;
public:
    void start() { timePoint = std::chrono::steady_clock::now(); }
    void finish() {
        auto curr = std::chrono::steady_clock::now();    
        auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(curr - timePoint);
        value = elapsed.count();
    }
    size_t operator()() const { return value; }
} timer;

uint32_t x32 = 314159265;
uint32_t xorshift32()
{ // fastest random generator
  x32 ^= x32 << 13;
  x32 ^= x32 >> 17;
  x32 ^= x32 << 5;
  return x32;
}

int main() {
	unsigned mod; std::cin >> mod;
	std::vector<uint32_t> data(1 << 16);
	for (auto& it : data) it = xorshift32();
	timer.start();
	uint32_t prod=1;
	for (int iter = 0; iter < 1000; iter++) {
		for (auto it : data) {
			prod = fast_mod(uint64_t(prod)*it,mod);
		}
	}
	timer.finish();
	std::cout << "prod1 = " << prod << ", runtime1 = " << timer() << "ms" << std::endl;
	timer.start();
	prod=1;
	for (int iter = 0; iter < 1000; iter++) {
		for (auto it : data) {
			prod = uint64_t(prod) * it % mod;
		}
	}
	timer.finish();
	std::cout << "prod2 = " << prod << ", runtime2 = " << timer() << "ms" << std::endl;
}