CSU-1446 modified LCs

Source: Internet
Author: User

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 ;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.