lab12
Fermats Theorem – Program #include <iostream> #include <cmath> using namespace std; // Function to perform modular exponentiation (a^exp % mod) long long modExp(long long base, long long exp, long long mod) { long long result = 1; base = base % mod; // Reduce base if it is larger than mod while (exp > 0) { if (exp % 2 == 1) // If exponent is odd result = (result * base) % mod; base = (base * base) % mod; // Square base exp /= 2; // Divide exponent by 2 } return result; } // Function to demonstrate Fermat's Little Theorem void fermatTheoremDemo() { long long a, p; // Input prime number p cout << "Enter a prime number (p): "; cin >> p; // Input integer a (not divisible by p) cout << "Enter an integer a (a should not be divisible by p): "; cin >> a; if (a % p == 0) { cout << "Error: 'a' should not be divisible by 'p'." << endl; return; } // Compute a^(p-1) % p ...