Question

Find the smallest strong pseudoprime to the base 3 in the interval [700, 800]. Kindly show...

Find the smallest strong pseudoprime to the base 3 in the interval [700, 800]. Kindly show all trials without using any programming language code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code in cpp:


#include <bits/stdc++.h>
using namespace std;

// Function to check if the given number is composite
bool checkcomposite(int n)
{
   // Check if there is any divisor of n less than sqrt(n)
   for (int i = 2; i <= sqrt(n); i++) {
       if (n % i == 0)
           return 1;
   }
   return 0;
}

// Effectively calculate (x^y) modulo mod
int power(int x, int y, int mod)
{

   // Initialize result
   int res = 1;

   while (y) {

       // If power is odd, then update the answer
       if ((y %2)== 1)
           res = (res * x) % mod;

       // Square the number and reduce
       // the power to its half
       y = y >> 1;
       x = (x * x) % mod;
   }

   // Return the result
   return res;
}

// Function to check for Fermat(strong) Pseudoprime
bool Check(int n, int a)
{

   // If it is composite and satisfy Fermat criterion
   if (a>1 && checkcomposite(n) && power(a, n - 1, n) == 1)
       return 1;

   // Else return 0
   return 0;
}


int main()
{

   int a=3;//to the base which we want to find
  
// Function call
   for(int i=700;i<=800;i++){
       if(Check(i, a)){
           cout<<i<<endl;
           break;
       }
   }
  

output:-

703

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Find the smallest strong pseudoprime to the base 3 in the interval [700, 800]. Kindly show...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT