1155C - Alarm Clocks Everywhere - CodeForces Solution


math number theory *1300

Please click on ads to support us..

C++ Code:

/*
Problem: 1155C
Date: 16-01-2024 03:43 AM
*/


#include <iostream>

using namespace std;

int n, m;
long long x0, g;
long long x[300000], p[300000];

long long gcd(long long a, long long b) {
	long long r;
	do {
		r = a % b;
		a = b;
		b = r;
	}while(r != 0);
	return a;
}

int main() {
	cin >> n >> m >> x0;
	for(int i = 1; i < n; i++) {
		cin >> x[i];
		x[i] -= x0;
		if(i == 1) g = x[i];
		else g = gcd(g, x[i]);
	}
	for(int i = 0; i < m; i++) {
		cin >> p[i];
	}
	for(int i = 0; i < m; i++) {
		if(g % p[i] == 0) {
			cout << "YES" << endl << x0 << " " << (i + 1) << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}


Comments

Submit
0 Comments
More Questions

677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets
1703B - ICPC Balloons
1702F - Equate Multisets
1700A - Optimal Path
665C - Simple Strings
1708A - Difference Operations
1703E - Mirror Grid
1042A - Benches
1676B - Equal Candies
1705B - Mark the Dust Sweeper
1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets