Saleh127

UVA 10006

Jul 20th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define maX 1000008
  7. bool marked[maX];
  8. void sieve()
  9. {
  10. marked[0]=1;
  11. marked[1]=1;
  12. for(ll i=4;i<=maX;i+=2)
  13. {
  14. marked[i]=1;
  15. }
  16. for(ll i=3;i<=maX;i+=2)
  17. {
  18. if(marked[i]==0)
  19. {
  20. for(ll j=i*i; j<=maX; j+=i+i)
  21. {
  22. marked[j]=1;
  23. }
  24. }
  25. }
  26. }
  27. ll mod(ll a,ll n,ll m)
  28. {
  29. if(n==0) return 1;
  30. ll x=mod(a,n/2,m);
  31. x=(x*x)%m;
  32. if(n%2==1)
  33. {
  34. x=(x*a)%m;
  35. }
  36. return x;
  37. }
  38. int main()
  39. {
  40. fellow_junior
  41. sieve();
  42. ll a,c,d,n,i,j,k,l;
  43. while(cin>>n &&n)
  44. {
  45. if(marked[n]==0)
  46. {
  47. cout<<n<<" is normal."<<endl;
  48. continue;
  49. }
  50. d=0;
  51. for(i=2;i<n;i++)
  52. {
  53. a=mod(i,n,n);
  54. if(i!=a)
  55. {
  56. d=1;
  57. break;
  58. }
  59. }
  60. if(d) cout<<n<<" is normal."<<endl;
  61. else
  62. {
  63. cout<<"The number "<<n<<" is a Carmichael number."<<endl;
  64. }
  65. }
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment