Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Remonhasan/2b219bfe4f67f707c6d36a046078c17f to your computer and use it in GitHub Desktop.
Save Remonhasan/2b219bfe4f67f707c6d36a046078c17f to your computer and use it in GitHub Desktop.
Chinese Reminder Theorem : Concept 01 [ Reminder ]
/* Author : Remon Hasan
Concept: Chinese Reminder Theorem [concept 1]
University of Asia Pacific
*/
#include<bits/stdc++.h>
using namespace std;
int find(int n[], int r[], int k)
{
int x=1;
while(true)
{
int i;
for(i=0;i<k;i++)
{
if(x%n[i]!=r[i])
break;
}
if(i==k)
return x;
x++;
}
return x;
}
int main ()
{
int n[]={3,4,5}; // number array -> x -> n[0]%3 = 2 , n[1]%4=3 , n[2]%5 = 1
int r[]={2,3,1}; // reminder array
int k = sizeof(n)/sizeof(n[0]);
cout<<"x is"<<find(n,r,k);
return 0;
}
@rhrazu
Copy link

rhrazu commented Mar 2, 2021

Go ahead do the next _____

@Remonhasan
Copy link
Author

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment