Uva 10006-carmichael Numbers (Fast power)

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions: Give a number n, ask whether this number is Carmichael Numbers,carmichael Numbers is defined as: A number n if not a prime and for any 2=<a<n to satisfy A^n%n=a, So this number is Carmichael Numbers, otherwise not. Quick power to solve the violence.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 65002#define _ll __int64#define ll Long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long longusing names Pace Std;ll N;bool pri[maxn];void init () {memset (PRI, 1, sizeof (PRI));p ri[0] = 0;pri[1] = 0;for (int i = 2; I * I <= max N i++) {if (Pri[i]) {for (int j = i * i; j <= Maxn; j + = i) {Pri[j] = 0;}}} ll Pow_mod (ll A, ll N, ll p) {if (n = = 0) {return 1;} ll ans = pow_mod (A, N/2, p); ans = ans * ans% p;if (n & 1) {ans = ans * a% P;} return ans;} void Solve () {if (Pri[n]) {printf ("%d is normal.\n", n); return;} for (ll i = 2; i < n; i++) {if (Pow_mod (i, n, n)! = i) {printf ("%d is normal.\n", n); return;}} printf ("The number%D is a Carmichael number.\n ", n);} int main () {init (); while (~SCANF ("%lld", &n) && N) {solve ();} return 0;}



Uva 10006-carmichael Numbers (Fast power)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.