2-topshiriq 1091 soni ferma ususli #include int main { int a = 2; int n = 1091; // Fermaning kichik teoremasini hisoblash int result = 1; for (int i = 0; i < n 1; ++i) { result = (result a) n; } // Natijani chiqarish std:: cout
int result = 1;
for (int i = 0; i < n - 1; ++i) {
result = (result * a) % n;
}
// Natijani chiqarish
std::cout << result << std::endl;
return 0;
}
a=17; #include
int main() {
int a = 17;
int n = 1091;
// Fermaning kichik teoremasini hisoblash
int result = 1;
for (int i = 0; i < n - 1; ++i) {
result = (result * a) % n;
}
// Natijani chiqarish
std::cout << result << std::endl;
return 0;
}
2. #include #include #include
// (a^b) % mod
long long power(long long a, long long b, long long mod) {
long long result = 1;
a = a % mod;
while (b > 0) {
if (b % 2 == 1)
result = (result * a) % mod;
b = b / 2;
a = (a * a) % mod;
}
return result;
}