Created
May 30, 2020 13:02
-
-
Save Remonhasan/2b219bfe4f67f707c6d36a046078c17f to your computer and use it in GitHub Desktop.
Chinese Reminder Theorem : Concept 01 [ Reminder ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go ahead do the next _____