Question

In: Computer Science

Using the Fermat primality test, find the number of Fermat witness and number of Fermat liars...

Using the Fermat primality test, find the number of Fermat witness and number of Fermat liars for 341 via computer programming (ex;c++).

Solutions

Expert Solution

Copyable Code

//Include the needed headers
#include <cstring>
#include <iostream>
#include <cstdlib>
#define longlong long long
using namespace std;

//Method modulo()
longlong modulo(longlong base, longlong expo, longlong mod)
{
   // Declare and initialize variables
   longlong c = 1;
   longlong d = base;

   //Loop till the condition satisfies
   while (expo > 0)
   {
       //Check condition
       if (expo % 2 == 1)

           //Compute c
           c = (c * d) % mod;

       //Compute d
       d = (d * d) % mod;

       //Compute exponent
       expo = expo / 2;
   }

   //Return value
   return c % mod;
}

//Method Fermat()
bool Fermat(longlong p, int noOfIterations)
{
   // Declare and initialize variables
   int fLiars = 0;
   int fWitness = 0;

   //Check condition
   if (p == 1)
   {
       //Return
       return false;
   }

   //Loop through noOfIterations
   for (int i = 0; i < noOfIterations; i++)
   {
       //Declare and initialize a
       longlong a = rand() % (p - 1) + 1;

       //Check condition
       if (modulo(a, p - 1, p) != 1)
       {
           //Increment fermat liars
           fLiars++;

           //Display fermat liar
           cout << " Number of Fermat lairs: " << fLiars;
          
           //Return
           return false;
       }
   }

   //Increment fermat witness
   fWitness++;

   //Display fermat witness
   cout << " Number of Fermat witness: " << fLiars;

   //Return
   return true;
}

//Method main()
int main()
{
   //Declare and initialize iteration
   int iteration = 50;

   //Declare a variable for input
   longlong input;

   //Prompt for input
   cout << " Enter an input to test primality: ";

   //Read input
   cin >> input;

   //Check condition
   if (Fermat(input, iteration))

       //Display result
       cout << " " << input << " is prime" << endl;

   //Otherwise
   else
       //Display result
       cout << " " << input << " is not prime" << endl;

   //Pause
   getchar(); getchar();

   //Return
   return 0;
}


Related Solutions

Under the Neil v. Biggers test for witness identification, what are the constitutional requirements that must...
Under the Neil v. Biggers test for witness identification, what are the constitutional requirements that must be met in order to allow the admissibility of evidence of a victim’s or witness’s pretrial identification of the defendant from photographs or a lineup?
What is an Expert Witness? What is the purpose of an Expert Witness? Who can be...
What is an Expert Witness? What is the purpose of an Expert Witness? Who can be an Expert Witness? What qualifies a person to be an expert witness?
Find the most powerful test using neyman pearson lemma.
Find the most powerful test using neyman pearson lemma.
(In this problem first find the probability by using SPSS and then calculate the number of...
(In this problem first find the probability by using SPSS and then calculate the number of trees manually by using the probabilities.) A certain variety of pine tree has a mean trunk diameter of μ=150 cm, and a standard deviation of σ=30 cm which is normally distributed. A certain section of a forest has 500 of these trees. Find Approximately 1. how many of these trees have a diameter smaller than 120 2. how many of these trees have a...
Find the difference between the two groups when using a dependent t-test then find the independent two-sample t-test
data = X1= 14, 8, 6, 14, 20, 13, 9, 12 x2= 13, 4, 1, 8, 10, 12, 8, 6 1. Find the difference between the two groups when using a dependent t-test then find the independent two-sample t-test, and compare the results with those from the dependent t-test
Using Ellman’s reagent, find the number of cysteines in a protein that has a concentration of...
Using Ellman’s reagent, find the number of cysteines in a protein that has a concentration of 30 mg/ml solution with a molecular weight of 15,000 Da. Data-- 0.1 ml of the protein was reacted with the reagent and diluted to 10 ml and the absorbance at 412 nm was 1.4 A. Hint, first find the moles of protein used for the experiment, then calculate the moles of Ellman’s reagent that reacted
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 3 Search list for some items as follows: a. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.) b. Use the binary search algorithm to search the list, switching to a sequentialsearch when the size...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 2 Use any sorting algorithm to sort list.
In C++ Write a program to find the number of comparisons using binarySearch and the sequential...
In C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 5.1 Use a random number generator to fill list.
Write a program in C++ to find the number of comparisons using binarySearch and the sequential...
Write a program in C++ to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. a. Use a random number generator to fill list. b. Use any sorting algorithm to sort list. c. Search list for some items as follows: i. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT