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

ld ModInv(ld b, ld n){
  ld r1=n,r2=b,t1=0,t2=1;
  while(r2>0){
    ld q=r1/r2;
    ld r=r1-q*r2;
    r1=r2;r2=r;
    ld t=t1-q*t2;
    t1=t2;t2=t;
  }
  if(t1<0)t1+=n;
  return t1;
}

ld powerLL(ld x, ld n, ld MOD) { 
	ld result = 1; 
	while (n) { 
		if (n&1) 
			result = result * x % MOD; 
		n = n / 2; 
		x = x * x % MOD; 
	} 
	return result; 
} 

ld powerStrings(string sa, string sb, ld MOD) { 

	ld a = 0, b = 0; 
	for (int i = 0; i < sa.length(); i++) 
		a = (a * 10 + (sa[i] - '0')) % MOD; 

	for (int i = 0; i < sb.length(); i++) 
		b = (b * 10 + (sb[i] - '0')) % (MOD - 1); 
	return powerLL(a, b, MOD); 
} 

ld mod(string num, ld a) { 
	ld res = 0; 

	// One by one process all digits of 'num' 
	for (int i = 0; i < num.length(); i++) 
		res = (res*10 + (int)num[i] - '0') %a; 

	return res; 
} 




int main(){
  ld p,e1,d,m,r,MOD;
  cin>>p>>e1>>d>>m>>r;
  ld e2,s1,s2,v1,v2,a,b;
  e2=powerStrings(to_string(e1),to_string(d),p);if(e2<0)e2+=p;
  s1=powerStrings(to_string(e1),to_string(r),p);if(s1<0)s1+=p;
  s2=(((m-d*s1)%(p-1))*ModInv(r,p-1))%(p-1);if(s2<0)s2+=(p-1);
  v1=powerStrings(to_string(e1),to_string(m),p);if(v1<0)v1+=p;
  a=powerStrings(to_string(e2),to_string(s1),p);if(a<0)a+=p;
  b=powerStrings(to_string(s1),to_string(s2),p);if(b<0)b+=p;
  v2=(a*b)%p;
  cout<<"e2="<<e2<<"\n";
  cout<<"s1="<<s1<<"\n";
  cout<<"s2="<<s2<<"\n";
  cout<<"v1="<<v1<<"\n";
  cout<<"v2="<<v2<<"\n";
  
  
    
}







 
by

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}