1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sever21 [200]
4 years ago
11

Write a program where you implement Modular Exponentiation (ME) using the square and multiplyapproach as a function which is cal

led in main. ME calculates a^k mod n. The program should get valuesfor a, k and n from the user. This code requires two steps. First k must be converted to a binaryrepresentation K consisting of a list of 0s and 1s. Second, Modular Exponentiation must be performedusing a, n and K[] as arguments.procedureBinaryK(k)K = empty list //hint: make K a vectortmp = ki = 0while tmp > 0add y mod 2 to K //hint: use pushbacktmp = (tmp-K[i])/2i++return KprocedureModularExpo(a, K, n)if n = 1return 0b = 1if k = 0return bA = aif K[0] = 1b = afor i = 1 to length(K)-1A = A*A mod nif K[i] = 1b = A*b mod nreturn b
Engineering
1 answer:
Eddi Din [679]4 years ago
8 0

Answer:

Explanation:

#include <iostream>

#include<vector>

using namespace std;

//calculating k value in binary digits

vector<int> BinaryK(int k){

  vector<int> temp;

  int r;

 

  while(k!=0)

  {

  r = k%2; //getting binary value at every step

  temp.push_back(r);

  k /= 2;

  }

  return temp;

}

int ModularExpo(int a, vector<int> k, int n){

  if(n == 1){ //if denominator is 1

      return 0;

  }

  int b = 1;

 

  bool zeros = std::all_of(k.begin(), k.end(), [](int i) { return i==0; }); //checking denominator is zero vector

  if(zeros){

      return b;

  }

 

  int A = a;

  if(k[0] == 1){

      b = a;

  }

  for(int i=0;i<k.size();i++){

      A = (A*A) % n;

      if(k[i] == 1){

          b = (A*b)%n;

      }

  }

  return b;

}

int main(){

  //declaring variables

  int a,k,n;

 

  //reading variables

  cout<<"Reading a: ";

  cin>>a;

  cout<<"Reading k: ";

  cin>>k;

  cout<<"Enter n: ";

  cin>>n;

 

  //declaring vector

  vector<int> vec;

  //calling functions

  vec = BinaryK(k);

  cout<<"Result is: "<<ModularExpo(a,vec,n);

  return 0;

}

You might be interested in
How can you do this 5.2.4: Rating?
gizmo_the_mogwai [7]

Answer:

whats the question

Explanation:

5 0
3 years ago
A commuter train traveling at 50 mi/h is 3 mi from a station. The train then decelerates so that its speed is 15 mi/h when it is
jonny [76]

Answer:

a) t = 277.477\,s\,(4.625\min), b) v_{f} = 0\,\frac{mi}{h}, c) a = -0.128\,\frac{ft}{s^{2}}

Explanation:

a) The deceleration experimented by the commuter train in the first 2.5 miles is:

a=\frac{[(15\,\frac{mi}{h} )\cdot (\frac{5280\,ft}{1\,mi} )\cdot (\frac{1\,h}{3600\,s} )]^{2}-[(50\,\frac{mi}{h} )\cdot (\frac{5280\,ft}{1\,mi} )\cdot (\frac{1\,h}{3600\,s} )]^{2}}{2\cdot (2.5\,mi)\cdot (\frac{5280\,ft}{1\,mi} )}

a = -0.185\,\frac{ft}{s^{2}}

The time required to travel is:

t = \frac{(15\,\frac{mi}{h} )\cdot (\frac{5280\,ft}{1\,fi} )\cdot(\frac{1\,h}{3600\,s} )-(50\,\frac{mi}{h} )\cdot (\frac{5280\,ft}{1\,fi} )\cdot(\frac{1\,h}{3600\,s} )}{-0.185\,\frac{ft}{s^{2}} }

t = 277.477\,s\,(4.625\min)

b) The commuter train must stop when it reaches the station to receive passengers. Hence, speed of train must be v_{f} = 0\,\frac{mi}{h}.

c) The final constant deceleration is:

a = \frac{(0\,\frac{mi}{h} )\cdot (\frac{5280\,ft}{1\,mi} )\cdot(\frac{1\,h}{3600\,s} )-(15\,\frac{mi}{h} )\cdot (\frac{5280\,ft}{1\,mi} )\cdot(\frac{1\,h}{3600\,s} )}{(2.875\,min)\cdot (\frac{60\,s}{1\,min} )}

a = -0.128\,\frac{ft}{s^{2}}

7 0
4 years ago
Assume the following LTI system where the input signal is an impulse train (i.e.,x(t)=∑????(t−nT0)[infinity]n=−[infinity].a)Find
Igoryamba

Answer:

See explaination

Explanation:

The Fourier transform of y(t) = x(t - to) is Y(w) = e- jwto X(w) . Therefore the magnitude spectrum of y(t) is given by

|Y(w)| = |X(w)|

The phase spectrum of y(t) is given by

<Y(w) = -wto + <X(w)

please kindly see attachment for the step by step solution of the given problem.

4 0
3 years ago
a vertical cylindrical container is being cooled in ambient air at 25 °C with no air circulation. if the initial temperature of
Sloan [31]

Answer:

the surface heat-transfer coefficient due to natural convection during the initial cooling period.  = 4.93 w/m²k

Explanation:

check attachement for answer explanation

7 0
3 years ago
Read 2 more answers
A 625 g basketball and a 58.5 g tennis ball are dropped from a height of d = 1.5 m onto the floor. The coefficient of restitutio
stich3 [128]

Answer:

Maximum height=7.3535 m

Explanation:

Solution of the problem is given in the attachments.

3 0
3 years ago
Other questions:
  • Nitrogen enters a steady-flow heat exchanger at 150 kPa, 10°C, and 100 m/s, and it receives heat as it flows through it. Nitroge
    15·1 answer
  • A car air-conditioning unit has a 0.5-kg aluminum storage cylinder that is sealed with a valve, and itcontains 2 L of refrigeran
    5·1 answer
  • A cylindrical tank with a radius of 2-m is filled with oil and water. The water has a density of rho = 1000 kg/m3 while the oil
    6·1 answer
  • Table 1(a) shows the marks obtained by 40 students in an examination
    11·1 answer
  • A Carnot heat engine absorbs 235 KW of heat from a heat source and rejects 164 KW to the atmosphere. Determine the thermal effic
    7·1 answer
  • How can you drop two eggs the feweHow can you drop two eggs the fewest amount of times, without them breaking? ...st amount of t
    13·2 answers
  • Estimate (a) the maximum, and (b) the minimum thermal conductivity values (in W/m-K) for a cermet that contains 76 vol% carbide
    9·1 answer
  • GMA MIG weiding is a
    7·1 answer
  • Christopher has designed a fluid power system that repeatedly gets clogs. Which of the following objects should he choose to add
    13·1 answer
  • How many different powerball combinations are there
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!