Lab Problem
Lab Problem
#include<iostream>
using namespace std;
int main()
{
int n=11,p=23,d=10,res=1;
while(d--)
{
res=(res*n)%p;
}
if(res<0)
res+=p;
cout<<"Output:"<<endl;
cout<<res;
OUTPUT
2
2.Find the remainder when 𝟓𝟗𝟎𝟒 is divided by 19
#include<iostream>
using namespace std;
int main()
{
//fermats theroem implies 5^18=1(mod19)
//writing 904=18*q+r
int r=904%18,rem;
if(r<0)
r+=18;
rem=r;
int p=19,n=5,res=1;
while(r--)
{
res=(res*n)%p;
}
if(res<0)
res+=p;
cout<<"904= "<<(904/18)<<"*18+"<<rem<<endl;
cout<<"Output:"<<endl;
cout<<res;
OUTPUT
17
3. Find the digit in the unit and tens place of 𝟏𝟐𝟑𝟐𝟒 .
#include<iostream>
using namespace std;
int main()
{
//units place is given by mod10
int n=12,d=324,u=1,t=1;
for(int i=0;i<d;i++)
{
u=(u*n)%10;
}
if(u<0)
u+=10;
//tens place is mod100/10
for(int i=0;i<d;i++)
t=(t*n)%100;
if(t<0)
t+=100;
t/=10;
cout<<"Output:"<<endl;
cout<<"Unit's Place:"<<u<<endl;
cout<<"Ten's Place:"<<t<<endl;
OUTPUT
Unit’s Place :6
Ten’s Place: 3
4.Find ∅(𝟒𝟑𝟓𝟔) and 𝝈(𝟑𝟐𝟒𝟗)
#include<bits/stdc++.h>
int main()
{
int phi=0;
num=4356;
cout<<"Output:"<<endl;
cout<<"Phi:"<<phi<<endl;
cout<<"Sigma:"<<sigma<<endl;
}
OUTPUT
Phi:1320
Sigma:4953
5.Solve the Diaphontine equation 𝟖𝟑𝟕𝒙 + 𝟗𝟐𝟓𝒚 = 𝟐𝟓𝟗𝟗𝟎
#include<iostream>
using namespace std;
return gcd;
}
int main()
{
int a=837,b=925,c=25990;
int g,x,y;
g=gcdExtended(a,b,&x,&y);
if(c%g)
{
cout<<"No solutions";
return 0;
}
x*=(c/g);
y*=(c/g);
cout<<"Output:"<<endl;
cout<<"x="<<x<<" y="<<y;
}
OUTPUT
x=-11747480 y=10629910
6.Solve the system of the congruences 𝒙 ≡ 𝟓(𝒎𝒐𝒅 𝟗)
𝒙 ≡ 𝟏𝟏(𝒎𝒐𝒅 𝟏𝟕)
𝒙 ≡ 𝟏𝟕(𝒎𝒐𝒅 𝟑𝟐) .
#include<iostream>
using namespace std;
if (m == 1)
return 0;
t = m;
t = x0;
x0 = x1 - q * x0;
x1 = t;
}
// Make x1 positive
if (x1 < 0)
x1 += m0;
return x1;
}
// number x such that:
// x % num[0] = rem[0],
// x % num[1] = rem[1],
// ..................
// x % num[k-2] = rem[k-1]
int findMinX(int num[], int rem[], int k)
{
// Compute product of all numbers
int prod = 1;
for (int i = 0; i < k; i++)
prod *= num[i];
// Initialize result
int result = 0;
// Apply above formula
for (int i = 0; i < k; i++)
{
int pp = prod / num[i];
result += rem[i] * inv(pp, num[i]) * pp;
}
cout<<"Output:"<<endl;
cout<<"x="<<x;
OUTPUT
x=113
7.Find the order of 𝟕(𝒎𝒐𝒅 𝟑𝟏)
#include<iostream>
using namespace std;
int main()
{
//finding the first power when 7^d=1mod(31)
int p=31,n=7,phi=30,res=1,d;
for(int i=1;;i++)
{
res=(res*n)%p;
if(res<0)
res+=p;
if(res==1)
{ d=i;
break;
}
}
cout<<"Output:"<<endl;
cout<<"Order is: "<<d;
}
OUTPUT
Order is: 15
8.Find the primitive roots of 29, 37.
#include<bits/stdc++.h>
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
int findPrimitive(int n)
{
unordered_set<int> s;
}
OUTPUT
9.Find solutions of the congruence 𝒙𝟒 = 𝟕(𝒎𝒐𝒅 𝟑𝟕) .
#include<bits/stdc++.h>
int main()
{
int p=37,r;
cout<<"Solutions are:"<<endl;
for(int i=1;i<=p;i++)
{
r=(i*i*i*i)%p;
if(r<0)
r+=p;
if(r==7)
cout<<i<<" ";
}
OUTPUT
Solutions are:
3 18 19 34
10.Find the quadratic residues of 17.
#include<bits/stdc++.h>
int main()
{
//17 is an odd prime so 0^2,1^2,...,(p-1/2)^2 are the q.r
int p=17,r;
cout<<"Q.r's of 17 are:"<<endl;
for(int i=0;i<=(p-1)/2;i++)
{
r=(i*i)%p;
if(r<0)
r+=p;
cout<<r<<" ";
}
OUTPUT
Q.r's of 17 are:
0 1 4 9 16 8 2 15 13
11.Find the continued fraction of 357/183.
#include<iostream>
using namespace std;
int arr[1000];
int main()
{
int p=357,q=183,ind=0,t;
while(p&&q)
{
arr[ind++]=p/q;
p=(p-(q*(p/q)));
t=q;
q=p;
p=t;
cout<<"Output:"<<endl;
for(int i=0;i<ind;i++)
cout<<arr[i]<<" ";
OUTPUT
1 1 19 3
Lab Problems
Number Theory
Gampa
Phanideep
IDD Part-IV
15123004