First collision point of two series | CPP program to calculate the colliding point of two series ; Iterating through n terms of the first series ; x is i - th term of first series ; d is first element of second series and c is common difference for second series . ; If no term of first series is found ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void point ( int a , int b , int c , int d , int n ) { int x , flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x = b + i * a ; if ( ( x - d ) % c == 0 and x - d >= 0 ) { cout << x << endl ; flag = 1 ; break ; } } if ( flag == 0 ) { cout << " No ▁ collision ▁ point " << endl ; } } int main ( ) { int a = 20 ; int b = 2 ; int c = 9 ; int d = 19 ; int n = 20 ; point ( a , b , c , d , n ) ; return 0 ; }