fo34 Giai đoạn số

View as PDF

Submit solution

Points: 100.00 (partial)
Time limit: 0.65s
Memory limit: 256M
Input: stdin
Output: stdout

Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Giai đoạn số

Cho hai đoạn đại số ~[a; b]~ và ~[c; d]~. Hãy tính số các số nguyên thuộc giao ~[a; b] ∩ [c; d]~.

Input

  • Dòng đầu ghi hai số nguyên a và b (-~10^{16} ≤a ≤ b ≤ 10^{16}~).
  • Dòng hai ghi hai số nguyên c và d (-~10^{16} ≤ c≤ d ≤ 10^{16}~).

    Output

Ghi ra một dòng là số các số nguyên thuộc giao ~[a; b] ∩ [c; d]~

Ví dụ:

Giaidoanso.inp Giaidoanso.out
1 5
3 7
3

Comments

Please read the guidelines before commenting.



  • -1
    xuanbao  commented on Feb. 25, 2026, 8:57 a.m. edited

    tt


  • -1
    hoangnam12345  commented on Jan. 10, 2026, 1:30 p.m.

    include <bits/stdc++.h>

    using namespace std;

    int main() { long long a,b,c,d;cin>>a>>b>>c>>d; long long x=max(a,c); long long y=min(b,d); if(x<=y) { cout<<y-x+1; } else { cout<<0; } return 0; }


  • -1
    truong_quoc_tien1234  commented on Aug. 19, 2025, 1:15 a.m.

    chịu luôn á


  • -1
    hungdz_1  commented on June 19, 2025, 8:05 a.m.

    ai giải bài này giúp với