Description
Input
Output
Sample Input
35 3 4 15 3 110 2 2 3 3100 1 100 1 2
Sample output
4350
Question: calculate the number of elements with the same equidifference Sequence
Idea: first, we can assume that the solution is F1 + D1 * k1 = F2 + D2 * K2. Then we can use the Extended Euclidean algorithm to find the smallest positive number solution, again when we know that a group of solutions is (x0, y0), any solution can be (x0 + kb ', y0-ka') {B '= B/GCD, a' = A/GCD}, which can be solved in their respective ranges. It is better to simulate the number of solutions in the processing range for ease of understanding.
# Include <iostream> # include <cstring> # include <cstdio> # include <algorithm> # include <cmath> typedef long ll; using namespace STD; ll x, y, g; void exgcd (ll a, LL B) {If (B = 0) {x = 1; y = 0; G = A; return;} exgcd (B, A % B); ll t = x; X = y; y = T-A/B * Y; return;} int main () {int t; ll N1, N2, f1, F2, D1, D2; scanf ("% d", & T); While (t --) {CIN> N1> F1> d1> N2> F2> D2; ll f = F2-F1; exgcd (D1,-D2 ); if (F % G) {printf ("0 \ n"); continue;} else {ll r = ABS (-D2)/g ); X = (x * F/g) % R + r) % R; y = (F-x * D1)/(-D2 ); ll dx = ABS (D1/g); ll dy = ABS (D2/g); LL ans = min (N1-1-x)/Dy, (n2-1-y)/dx) + 1; cout <ans <Endl ;}} return 0 ;}