uva 10006 Carmichael Numbers(快速幂+素数)
2014-12-30 13:13
417 查看
题意:
求数是否满足不是素数且能满足费马定理。(a ^ n mod n = a)
代码:
求数是否满足不是素数且能满足费马定理。(a ^ n mod n = a)
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> #include <cmath> #include <stack> #include <vector> #include <queue> #include <map> #include <climits> #include <cassert> #define LL long long using namespace std; const int maxn = 1e6; const int inf = 0x3f3f3f3f; const double eps = 1e-8; const double pi = 4 * atan(1.0); const double ee = exp(1.0); int pow_mod(int a, int n, int mod) { if (n == 0) return 1; int x = pow_mod(a, n >> 1, mod); LL ans = (LL)x * x % mod; if (n % 2) ans = ans * a % mod; return ans; } bool is_car(int x) { for (int i = 2; i <= x - 1; i++) { if (pow_mod(i, x, x) != i) { return false; } } return true; } bool is_prime(int x) { int m = sqrt(x); for (int i = 2; i <= m; i++) { if (x % i == 0) { return false; } } return true; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL int n; while (scanf("%d", &n) && n) { if (is_prime(n)) { printf("%d is normal.\n", n); } else { if (!is_car(n)) { printf("%d is normal.\n", n); } else { printf("The number %d is a Carmichael number.\n", n); } } } return 0; }
相关文章推荐
- UVa 10006 Carmichael Numbers 【快速幂+素数打表(埃氏筛法)】
- Uva 10006 - Carmichael Numbers【素数+快速幂取模】
- 【素数 && 快速幂】UVA - 10006 Carmichael Numbers
- UVA 10006 - Carmichael Numbers (快速幂+筛素数)
- UVA10006->素数筛&&快速幂取模
- Carmichael Numbers - UVa 10006 素数判断
- Uva 10006 Carmichael Numbers(数论、快速幂、素数筛法)
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
- UVA10006 - Carmichael Numbers(筛选构造素数表+快速幂)
- UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂)
- uva 10006 素数打表+幂取模(反复平方法)(O(logn))
- 快速幂取模 例题uva10006
- Uva 10006 Carmichael Numbers (快速幂)
- UVA - 10006 Carmichael Numbers - 快速幂
- UVA 10006 Carmichael Numbers (暴力+快速幂取模)
- Uva 10006 Carmichael Numbers 快速幂
- Uva10006【快速幂】java题解
- UVA 10006 - Carmichael Numbers(快速幂取模)
- UVA 10006 - Carmichael Numbers 快速幂
- UVA - 10006 Carmichael Numbers(素数筛+快速幂)