Advertisement
Saleh127

UVA 10956

Sep 21st, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  6.  
  7. ll bigmod(ll a,ll c,ll d)
  8. {
  9. if(c==0) return 1;
  10. ll x=bigmod(a,c/2,d);
  11. x=((ull)x*(ull)x)%d;
  12. if(c%2==1)
  13. {
  14. x=((ull)x*(ull)a)%d;
  15. }
  16. return x;
  17. }
  18.  
  19. bool xxx(ll a,ll n)
  20. {
  21.  
  22. if(n<2) return false;
  23. ll u=n-1,t=0;
  24.  
  25. while(u%2==0) u>>=1,t++;
  26.  
  27. ll x=bigmod(a,u,n);
  28.  
  29. if(x == 1 || x ==n-1) return true;
  30.  
  31. for(ll i=0; i<t-1; i++)
  32. {
  33. x=((ull)x * (ull)x) %n;
  34. if(x==1) return false;
  35. if(x==n-1) return true;
  36. }
  37. return false;
  38. }
  39.  
  40.  
  41.  
  42. int main()
  43. {
  44. ios_base::sync_with_stdio(0);
  45. cin.tie(0);
  46. cout.tie(0);
  47.  
  48. ll b,l,r,i,j,k,n,m=0,e,f,pr;
  49.  
  50. while(cin>>b>>l>>r && (b || l || r))
  51. {
  52. vector<ll>x;
  53.  
  54. pr=0;
  55.  
  56. for(i=l; i<=r; i++)
  57. {
  58. if(i%2==1)
  59. {
  60. if(!(xxx(2, i) && xxx(7, i) && xxx(61, i)))
  61. {
  62. pr++;
  63.  
  64. if(xxx(b,i))
  65. {
  66. x.push_back(i);
  67. }
  68. }
  69. }
  70. }
  71.  
  72.  
  73. if(m) cout<<endl;
  74. m=1;
  75.  
  76. cout<<"There are "<<pr<<" odd non-prime numbers between "<<l<<" and "<<r<<"."<<endl;
  77. if(x.size())
  78. {
  79. cout<<x.size()<<" suspects fail in base "<<b<<":"<<endl;
  80. for(auto dd:x)
  81. {
  82. cout<<dd<<endl;
  83. }
  84. }
  85. else
  86. {
  87. cout<<"There are no failures in base "<<b<<"."<<endl;
  88. }
  89.  
  90. x.clear();
  91.  
  92. }
  93.  
  94.  
  95. return 0;
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement