-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodular.cpp
More file actions
36 lines (36 loc) · 733 Bytes
/
modular.cpp
File metadata and controls
36 lines (36 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<string>
using namespace std;
long long p=1;
long long mod (string a,long long c,long long p){
if (a.length()==0) return 0;
return (mod(a.substr(0,a.length()-1),c,(p*10)%c)+((a[a.length()-1]-48)*p)%c)%c;
}
int main(){
cout<<"press 1 for modular addition 2 for subtraction 3 for multiplication"<<endl;
int command;cin>>command;
if(command==1){
cout<<"enter a,b,c ";
string a,b;
cin>>a>>b;
long long c;
cin>>c;
cout<<(mod(a,c,p)+mod(b,c,p))%c<<endl;
}
if(command==2){
cout<<"enter a,b,c ";
string a,b;
cin>>a>>b;
long long c;
cin>>c;
cout<<(mod(a,c,p)-mod(b,c,p))%c<<endl;
}
if(command==3){
cout<<"enter a,b,c ";
string a,b;
cin>>a>>b;
long long c;
cin>>c;
cout<<((mod(a,c,p))%c*(mod(b,c,p)%c))%c<<endl;
}
}