QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#495227#9141. Array Spreaducup-team1134#TL 1203ms3796kbC++2318.1kb2024-07-27 19:35:332024-07-27 19:35:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 18:58:44]
  • hack成功,自动添加数据
  • (/hack/840)
  • [2024-09-18 18:53:02]
  • hack成功,自动添加数据
  • (/hack/839)
  • [2024-07-29 03:53:23]
  • hack成功,自动添加数据
  • (/hack/753)
  • [2024-07-29 03:51:16]
  • hack成功,自动添加数据
  • (/hack/752)
  • [2024-07-29 03:50:24]
  • hack成功,自动添加数据
  • (/hack/751)
  • [2024-07-29 03:48:52]
  • hack成功,自动添加数据
  • (/hack/750)
  • [2024-07-27 19:35:33]
  • 评测
  • 测评结果:TL
  • 用时:1203ms
  • 内存:3796kb
  • [2024-07-27 19:35:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=4005,INF=15<<26;

//modintのみ

// from: https://gist.github.com/yosupo06/ddd51afb727600fd95d9d8ad6c3c80c9
// (based on AtCoder STL)

#include <cassert>
#include <numeric>
#include <type_traits>

namespace atcoder {
    
    namespace internal {
        
#ifndef _MSC_VER
        template <class T>
        using is_signed_int128 =
        typename std::conditional<std::is_same<T, __int128_t>::value ||
        std::is_same<T, __int128>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_unsigned_int128 =
        typename std::conditional<std::is_same<T, __uint128_t>::value ||
        std::is_same<T, unsigned __int128>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using make_unsigned_int128 =
        typename std::conditional<std::is_same<T, __int128_t>::value,
        __uint128_t,
        unsigned __int128>;
        
        template <class T>
        using is_integral = typename std::conditional<std::is_integral<T>::value ||
        is_signed_int128<T>::value ||
        is_unsigned_int128<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                         std::is_signed<T>::value) ||
        is_signed_int128<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_unsigned_int =
        typename std::conditional<(is_integral<T>::value &&
                                   std::is_unsigned<T>::value) ||
        is_unsigned_int128<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using to_unsigned = typename std::conditional<
        is_signed_int128<T>::value,
        make_unsigned_int128<T>,
        typename std::conditional<std::is_signed<T>::value,
        std::make_unsigned<T>,
        std::common_type<T>>::type>::type;
        
#else
        
        template <class T> using is_integral = typename std::is_integral<T>;
        
        template <class T>
        using is_signed_int =
        typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using is_unsigned_int =
        typename std::conditional<is_integral<T>::value &&
        std::is_unsigned<T>::value,
        std::true_type,
        std::false_type>::type;
        
        template <class T>
        using to_unsigned = typename std::conditional<is_signed_int<T>::value,
        std::make_unsigned<T>,
        std::common_type<T>>::type;
        
#endif
        
        template <class T>
        using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
        
        template <class T>
        using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
        
        template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
        
    }  // namespace internal
    
}  // namespace atcoder

#include <utility>

namespace atcoder {
    
    namespace internal {
        
        constexpr long long safe_mod(long long x, long long m) {
            x %= m;
            if (x < 0) x += m;
            return x;
        }
        
        struct barrett {
            unsigned int _m;
            unsigned long long im;
            
            barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
            
            unsigned int umod() const { return _m; }
            
            unsigned int mul(unsigned int a, unsigned int b) const {
                
                unsigned long long z = a;
                z *= b;
#ifdef _MSC_VER
                unsigned long long x;
                _umul128(z, im, &x);
#else
                unsigned long long x =
                (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
                unsigned int v = (unsigned int)(z - x * _m);
                if (_m <= v) v += _m;
                return v;
            }
        };
        
        constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
            if (m == 1) return 0;
            unsigned int _m = (unsigned int)(m);
            unsigned long long r = 1;
            unsigned long long y = safe_mod(x, m);
            while (n) {
                if (n & 1) r = (r * y) % _m;
                y = (y * y) % _m;
                n >>= 1;
            }
            return r;
        }
        
        constexpr bool is_prime_constexpr(int n) {
            if (n <= 1) return false;
            if (n == 2 || n == 7 || n == 61) return true;
            if (n % 2 == 0) return false;
            long long d = n - 1;
            while (d % 2 == 0) d /= 2;
            for (long long a : {2, 7, 61}) {
                long long t = d;
                long long y = pow_mod_constexpr(a, t, n);
                while (t != n - 1 && y != 1 && y != n - 1) {
                    y = y * y % n;
                    t <<= 1;
                }
                if (y != n - 1 && t % 2 == 0) {
                    return false;
                }
            }
            return true;
        }
        template <int n> constexpr bool is_prime = is_prime_constexpr(n);
        
        constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
            a = safe_mod(a, b);
            if (a == 0) return {b, 0};
            
            long long s = b, t = a;
            long long m0 = 0, m1 = 1;
            
            while (t) {
                long long u = s / t;
                s -= t * u;
                m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b
                
                
                auto tmp = s;
                s = t;
                t = tmp;
                tmp = m0;
                m0 = m1;
                m1 = tmp;
            }
            if (m0 < 0) m0 += b / s;
            return {s, m0};
        }
        
        constexpr int primitive_root_constexpr(int m) {
            if (m == 2) return 1;
            if (m == 167772161) return 3;
            if (m == 469762049) return 3;
            if (m == 754974721) return 11;
            if (m == 998244353) return 3;
            int divs[20] = {};
            divs[0] = 2;
            int cnt = 1;
            int x = (m - 1) / 2;
            while (x % 2 == 0) x /= 2;
            for (int i = 3; (long long)(i)*i <= x; i += 2) {
                if (x % i == 0) {
                    divs[cnt++] = i;
                    while (x % i == 0) {
                        x /= i;
                    }
                }
            }
            if (x > 1) {
                divs[cnt++] = x;
            }
            for (int g = 2;; g++) {
                bool ok = true;
                for (int i = 0; i < cnt; i++) {
                    if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                        ok = false;
                        break;
                    }
                }
                if (ok) return g;
            }
        }
        template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
        
    }  // namespace internal
    
}  // namespace atcoder

#include <cassert>
#include <numeric>
#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {
    
    namespace internal {
        
        struct modint_base {};
        struct static_modint_base : modint_base {};
        
        template <class T> using is_modint = std::is_base_of<modint_base, T>;
        template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
        
    }  // namespace internal
    
    template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
    struct static_modint : internal::static_modint_base {
        using mint = static_modint;
        
    public:
        static constexpr int mod() { return m; }
        static mint raw(int v) {
            mint x;
            x._v = v;
            return x;
        }
        
        static_modint() : _v(0) {}
        template <class T, internal::is_signed_int_t<T>* = nullptr>
        static_modint(T v) {
            long long x = (long long)(v % (long long)(umod()));
            if (x < 0) x += umod();
            _v = (unsigned int)(x);
        }
        template <class T, internal::is_unsigned_int_t<T>* = nullptr>
        static_modint(T v) {
            _v = (unsigned int)(v % umod());
        }
        static_modint(bool v) { _v = ((unsigned int)(v) % umod()); }
        
        unsigned int val() const { return _v; }
        
        mint& operator++() {
            _v++;
            if (_v == umod()) _v = 0;
            return *this;
        }
        mint& operator--() {
            if (_v == 0) _v = umod();
            _v--;
            return *this;
        }
        mint operator++(int) {
            mint result = *this;
            ++*this;
            return result;
        }
        mint operator--(int) {
            mint result = *this;
            --*this;
            return result;
        }
        
        mint& operator+=(const mint& rhs) {
            _v += rhs._v;
            if (_v >= umod()) _v -= umod();
            return *this;
        }
        mint& operator-=(const mint& rhs) {
            _v -= rhs._v;
            if (_v >= umod()) _v += umod();
            return *this;
        }
        mint& operator*=(const mint& rhs) {
            unsigned long long z = _v;
            z *= rhs._v;
            _v = (unsigned int)(z % umod());
            return *this;
        }
        mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
        
        mint operator+() const { return *this; }
        mint operator-() const { return mint() - *this; }
        
        mint pow(long long n) const {
            assert(0 <= n);
            mint x = *this, r = 1;
            while (n) {
                if (n & 1) r *= x;
                x *= x;
                n >>= 1;
            }
            return r;
        }
        mint inv() const {
            if (prime) {
                assert(_v);
                return pow(umod() - 2);
            } else {
                auto eg = internal::inv_gcd(_v, m);
                assert(eg.first == 1);
                return eg.second;
            }
        }
        
        friend mint operator+(const mint& lhs, const mint& rhs) {
            return mint(lhs) += rhs;
        }
        friend mint operator-(const mint& lhs, const mint& rhs) {
            return mint(lhs) -= rhs;
        }
        friend mint operator*(const mint& lhs, const mint& rhs) {
            return mint(lhs) *= rhs;
        }
        friend mint operator/(const mint& lhs, const mint& rhs) {
            return mint(lhs) /= rhs;
        }
        friend bool operator==(const mint& lhs, const mint& rhs) {
            return lhs._v == rhs._v;
        }
        friend bool operator!=(const mint& lhs, const mint& rhs) {
            return lhs._v != rhs._v;
        }
        
    private:
        unsigned int _v;
        static constexpr unsigned int umod() { return m; }
        static constexpr bool prime = internal::is_prime<m>;
    };
    
    template <int id> struct dynamic_modint : internal::modint_base {
        using mint = dynamic_modint;
        
    public:
        static int mod() { return (int)(bt.umod()); }
        static void set_mod(int m) {
            assert(1 <= m);
            bt = internal::barrett(m);
        }
        static mint raw(int v) {
            mint x;
            x._v = v;
            return x;
        }
        
        dynamic_modint() : _v(0) {}
        template <class T, internal::is_signed_int_t<T>* = nullptr>
        dynamic_modint(T v) {
            long long x = (long long)(v % (long long)(mod()));
            if (x < 0) x += mod();
            _v = (unsigned int)(x);
        }
        template <class T, internal::is_unsigned_int_t<T>* = nullptr>
        dynamic_modint(T v) {
            _v = (unsigned int)(v % mod());
        }
        dynamic_modint(bool v) { _v = ((unsigned int)(v) % mod()); }
        
        unsigned int val() const { return _v; }
        
        mint& operator++() {
            _v++;
            if (_v == umod()) _v = 0;
            return *this;
        }
        mint& operator--() {
            if (_v == 0) _v = umod();
            _v--;
            return *this;
        }
        mint operator++(int) {
            mint result = *this;
            ++*this;
            return result;
        }
        mint operator--(int) {
            mint result = *this;
            --*this;
            return result;
        }
        
        mint& operator+=(const mint& rhs) {
            _v += rhs._v;
            if (_v >= umod()) _v -= umod();
            return *this;
        }
        mint& operator-=(const mint& rhs) {
            _v += mod() - rhs._v;
            if (_v >= umod()) _v -= umod();
            return *this;
        }
        mint& operator*=(const mint& rhs) {
            _v = bt.mul(_v, rhs._v);
            return *this;
        }
        mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
        
        mint operator+() const { return *this; }
        mint operator-() const { return mint() - *this; }
        
        mint pow(long long n) const {
            assert(0 <= n);
            mint x = *this, r = 1;
            while (n) {
                if (n & 1) r *= x;
                x *= x;
                n >>= 1;
            }
            return r;
        }
        mint inv() const {
            auto eg = internal::inv_gcd(_v, mod());
            assert(eg.first == 1);
            return eg.second;
        }
        
        friend mint operator+(const mint& lhs, const mint& rhs) {
            return mint(lhs) += rhs;
        }
        friend mint operator-(const mint& lhs, const mint& rhs) {
            return mint(lhs) -= rhs;
        }
        friend mint operator*(const mint& lhs, const mint& rhs) {
            return mint(lhs) *= rhs;
        }
        friend mint operator/(const mint& lhs, const mint& rhs) {
            return mint(lhs) /= rhs;
        }
        friend bool operator==(const mint& lhs, const mint& rhs) {
            return lhs._v == rhs._v;
        }
        friend bool operator!=(const mint& lhs, const mint& rhs) {
            return lhs._v != rhs._v;
        }
        
    private:
        unsigned int _v;
        static internal::barrett bt;
        static unsigned int umod() { return bt.umod(); }
    };
    template <int id> internal::barrett dynamic_modint<id>::bt = 998244353;
    
    using modint998244353 = static_modint<998244353>;
    using modint1000000007 = static_modint<1000000007>;
    using modint = dynamic_modint<-1>;
    
    namespace internal {
        
        template <class T>
        using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
        
        template <class T>
        using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
        
        template <class> struct is_dynamic_modint : public std::false_type {};
        template <int id>
        struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
        
        template <class T>
        using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
        
    }  // namespace internal
    
}  // namespace atcoder

using mint=atcoder::modint998244353;

vector<pair<int,double>> G[MAX];
double dis[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int N,M;cin>>N>>M;
        vector<int> use,L(M),R(M);
        for(int i=0;i<M;i++){
            int a,b;cin>>a>>b;a--;
            use.push_back(a);
            use.push_back(b);
            L[i]=a;
            R[i]=b;
        }
        sort(all(use));
        use.erase(unique(all(use)),use.end());
        
        N=si(use);
        
        for(int i=0;i<N;i++) G[i].clear();
        
        for(int i=1;i<N;i++) G[i].push_back(mp(i-1,0));
        
        for(int i=0;i<M;i++){
            L[i]=lower_bound(all(use),L[i])-use.begin();
            R[i]=lower_bound(all(use),R[i])-use.begin();
            
            G[R[i]].push_back(mp(L[i],-1));
            G[L[i]].push_back(mp(R[i],-2));
        }
        
        double l=0,r=5000;
        for(int q=0;q<40;q++){
            double X=(l+r)/2;
            for(int i=0;i<N;i++) dis[i]=0;
            bool ok=true;
            for(int q=0;q<=N;q++){
                for(int i=0;i<N;i++){
                    for(auto [to,co]:G[i]){
                        if(co==-2){
                            if(chmin(dis[to],dis[i]+X)&&q==N) ok=false;
                        }else{
                            if(chmin(dis[to],dis[i]+co)&&q==N) ok=false;
                        }
                    }
                }
            }
            if(ok) r=X;
            else l=X;
        }
        pair<double,ll> gosa=mp(INF,-1);
        for(ll m=1;m<=N;m++){
            double z=l*m;
            double zz=roundl(z);
            chmin(gosa,mp(abs(zz-z),m));
        }
        
        double z=roundl(l*gosa.se);
        ll a=roundl(z),b=gosa.se;
        mint ans=a;
        ans/=b;
        cout<<ans.val()<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3756kb

input:

3
3 3
1 3
2 3
1 2
12 6
2 3
5 7
1 9
4 8
1 2
7 11
4 5
3 4
2 3
1 2
4 4
1 1

output:

1
2
499122178

result:

ok 3 number(s): "1 2 499122178"

Test #2:

score: 0
Accepted
time: 3ms
memory: 3612kb

input:

2000
1000000000 1
259923446 367011266
1000000000 1
882434225 971573327
1000000000 1
41585677 470369580
1000000000 1
371902212 947250194
1000000000 1
787209148 924205796
1000000000 1
259074809 960876164
1000000000 1
148079314 188254573
1000000000 1
940091047 948318624
1000000000 1
40636497 743979446
...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 2000 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 3568kb

input:

1000
1000000000 5
575330909 661595447
708422488 913945134
658050911 930246647
786571892 904549453
851755566 969150871
1000000000 2
198072104 844159589
8876188 644559580
1000000000 2
740802634 976972118
783909534 898449184
1000000000 2
871819537 941611957
465883854 640988372
1000000000 1
99458969 462...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 6ms
memory: 3692kb

input:

500
1000000000 13
964546318 987364574
367845944 907446075
259314137 890312338
458318546 959971971
353677471 522446336
782931403 845199078
514387878 786979588
532634932 793056892
905393511 960628299
747423889 986373313
796099347 833069525
906969434 971335651
574582540 647534593
1000000000 6
987712893...

output:

3
1
3
1
1
1
1
1
1
3
2
1
1
1
3
1
2
1
1
2
1
3
1
1
1
2
1
2
2
1
1
1
1
1
1
1
3
1
1
1
1
2
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
1
1
1
2
2
1
1
3
1
2
1
1
1
1
2
3
1
1
1
1
1
1
1
3
2
1
3
2
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
3
1
1
1
1
1
1
1
2
1
1
2
1
1
1
2
1
4
1
2
1
4
1
3
1
1
1
1
1
2
1
1
4
1
...

result:

ok 500 numbers

Test #5:

score: 0
Accepted
time: 20ms
memory: 3772kb

input:

250
1000000000 10
844342043 888135880
127033337 726074967
581308029 893912240
414276384 752837267
565680461 863374082
230362895 477723054
210479116 423381051
325072305 427826920
178306222 756423471
376470949 993759748
1000000000 2
468173597 607783582
266359996 863641680
1000000000 7
206599093 941381...

output:

2
1
2
1
3
3
1
1
1
2
1
2
2
1
3
5
2
1
1
1
2
1
2
1
3
1
2
1
3
499122178
1
1
1
1
3
1
1
1
3
3
3
1
4
1
1
1
1
1
1
1
1
5
1
4
2
1
3
1
1
1
2
5
2
1
2
6
2
2
1
2
1
1
1
5
8
2
1
2
1
1
2
2
2
1
1
5
8
3
1
1
1
8
2
6
1
1
4
2
1
1
1
1
2
2
1
2
1
1
1
1
1
1
2
1
2
1
1
4
1
1
3
1
2
3
3
2
5
1
1
1
3
2
1
1
1
3
1
1
2
1
1
1
1
3
1
1
...

result:

ok 250 numbers

Test #6:

score: 0
Accepted
time: 12ms
memory: 3628kb

input:

250
1000000000 4
10495745 465086423
465086424 609997778
396956207 663037010
253873206 396956206
1000000000 33
596279983 655818820
226461062 338625457
407323582 423049163
711408063 778512581
220274357 226461061
702491412 711408062
686978949 688730316
369564474 434159428
778512582 787885602
675683057 ...

output:

1
2
748683266
5
6
453747435
1
10
6
1
499122183
1
4
3
1
3
1
748683266
2
499122179
10
499122178
1
499122179
4
1
7
1
665496238
2
2
2
332748119
249561090
816745381
499122178
2
499122179
5
3
4
17
1
2
2
3
249561092
1
3
924300328
499122179
2
3
332748120
2
7
3
499122187
6
374341634
1
2
332748120
2
2
2
49912...

result:

ok 250 numbers

Test #7:

score: 0
Accepted
time: 45ms
memory: 3712kb

input:

100
1000000000 17
272213590 960979163
970159974 987653658
201788340 556786243
46564706 948945765
786605927 819103747
510930374 747773556
729597186 850647589
412727504 443334406
685627406 773178988
793614323 909668193
830162056 837607472
416766039 753918198
237455713 993045890
848459092 851118478
463...

output:

8
1
1
2
3
3
1
5
1
2
8
2
1
1
3
1
3
6
3
3
2
3
7
2
1
1
3
1
2
1
5
5
2
2
4
2
7
2
1
6
1
2
5
4
5
4
1
1
1
8
6
1
4
4
5
13
1
4
9
4
8
3
8
5
4
7
1
8
1
1
1
9
2
1
6
4
4
3
1
1
1
10
4
6
11
6
6
1
1
4
1
4
2
2
13
5
1
1
5
8

result:

ok 100 numbers

Test #8:

score: 0
Accepted
time: 51ms
memory: 3784kb

input:

100
1000000000 49
187775019 193881727
145323628 162242601
964365230 971504847
226437670 229819402
46971378 49331905
871327590 883354570
310535966 323031740
904117712 916571909
458902934 484636144
13320536 14923771
571938132 574937141
89751784 102733764
412667720 421251698
908036941 932886651
2663244...

output:

2
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
2
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
2
3
1
1
1
1
1
1
3
1
3
1
1
1
1
1
1
1
1
2
1
1
1
2
1
1
3
1
1
1
1
3
1
1
1
1
1
2
1
1
1
1
1
2
1
2
2
1
1
1

result:

ok 100 numbers

Test #9:

score: 0
Accepted
time: 53ms
memory: 3616kb

input:

100
1000000000 33
607773622 612059886
773446566 927093401
216659567 357373353
949986996 960422356
67865304 185683459
748675762 867719748
419805439 434936264
83601801 106508219
584299087 639485780
487166380 588591547
670602250 789210083
877816826 902687951
800334389 834278741
90815648 214176329
53952...

output:

4
1
4
6
3
1
1
7
1
1
3
3
1
4
4
1
2
4
1
5
1
2
2
1
2
9
2
1
2
2
1
2
1
2
4
2
2
1
1
3
2
2
2
1
1
1
1
4
1
1
2
1
1
1
2
1
7
1
1
1
6
2
1
3
6
4
10
1
1
3
5
1
1
10
8
1
3
1
1
2
3
1
1
6
1
2
1
2
3
3
2
4
1
3
2
7
1
1
1
1

result:

ok 100 numbers

Test #10:

score: 0
Accepted
time: 40ms
memory: 3788kb

input:

100
1000000000 27
423127198 447304856
209683651 219301129
831320345 879604518
631502329 814498734
130918283 202258454
434769186 463838309
448295746 500976275
778017547 864887407
60178254 66348236
615735891 725460273
78684718 129678593
219427409 221445385
242513397 378886240
549135209 710348598
24951...

output:

748683266
2
332748119
2
855638018
2
2
2
1
1
499122179
1
630470119
1
873463814
10
3
598946613
499122178
499122179
720954257
24956110
686292996
499122178
6
2
499122180
332748122
665496237
27
17
1
15
5
199648872
6
4
3
1
285212675
2
1
4
2
499122186
698771050
844668300
887328319
332748120
1
2
499122179
4...

result:

ok 100 numbers

Test #11:

score: 0
Accepted
time: 86ms
memory: 3636kb

input:

50
1000000000 54
393385964 584227315
530511168 878333402
240442438 693353417
66549203 383382851
432995043 781030135
902504635 941834946
40257869 409360381
186795487 285734229
500620269 578283640
769614926 881642580
651338390 854914246
220143804 506609845
486528251 695975933
659594236 951619961
26914...

output:

6
3
9
1
5
1
5
7
4
9
11
7
4
10
1
1
3
1
1
7
11
12
7
6
6
7
1
14
9
5
3
11
7
5
10
1
1
14
2
8
16
4
4
2
2
6
4
1
1
9

result:

ok 50 numbers

Test #12:

score: 0
Accepted
time: 3ms
memory: 3648kb

input:

50
10 65
7 10
3 6
5 7
7 7
3 9
2 2
3 10
10 10
7 7
2 3
5 6
7 10
3 9
2 8
2 8
8 8
4 8
9 9
9 9
7 9
1 1
3 6
9 10
9 10
2 3
7 8
9 10
2 9
9 10
10 10
5 7
6 10
6 8
4 5
10 10
5 5
5 10
8 8
1 9
6 7
3 6
1 9
2 5
1 10
2 9
8 9
8 8
1 1
2 9
4 9
10 10
7 10
2 3
8 9
10 10
2 4
2 9
4 7
1 3
1 9
10 10
1 4
8 9
7 8
7 8
10 88
6 ...

output:

7
8
7
6
4
4
6
4
6
8
7
6
6
3
499122178
3
3
7
10
4
2
3
5
2
8
2
8
1
4
7
4
4
7
6
1
4
2
5
3
6
4
2
1
6
1
6
3
9
6
4

result:

ok 50 numbers

Test #13:

score: 0
Accepted
time: 150ms
memory: 3740kb

input:

25
1000000000 126
107069149 368376053
479032115 765537110
991540256 997326292
403046092 722244014
490526523 516722534
274125538 310843747
777271932 894507975
30859549 117930127
295842439 932626190
696990395 727705976
919364307 981912430
452436750 754049053
436429356 707440965
255169020 717543449
875...

output:

13
12
14
15
3
8
13
499122178
9
17
3
3
5
6
6
22
3
3
16
6
17
5
6
9
19

result:

ok 25 numbers

Test #14:

score: 0
Accepted
time: 309ms
memory: 3704kb

input:

10
1000000000 69
870434015 950861762
463726401 635711398
333118041 890448132
290535922 477961269
413309490 468893401
200588542 259174530
820993949 902249431
919016091 952057155
32176623 226256591
307850591 328322116
544612131 956816575
794988232 980183910
896176727 934471390
445409718 674881616
3109...

output:

7
21
17
13
6
11
30
26
17
14

result:

ok 10 numbers

Test #15:

score: 0
Accepted
time: 693ms
memory: 3700kb

input:

10
1000000000 226
722573032 815472621
582575925 607010515
411370955 463267466
92061989 217643130
187859011 258319855
811376535 844552673
426496326 431292091
785538560 983675713
328209738 364768843
338697990 509158393
502285144 536085577
202590577 293138489
873383022 956559039
765186726 836986281
219...

output:

15
5
5
12
18
2
13
12
35
8

result:

ok 10 numbers

Test #16:

score: 0
Accepted
time: 3ms
memory: 3796kb

input:

10
10 31
7 8
5 9
2 4
6 10
10 10
4 5
3 6
8 8
4 10
7 8
2 8
2 7
3 4
9 9
4 7
1 8
1 10
3 9
2 5
5 8
5 8
5 8
6 6
2 10
3 7
9 10
9 10
7 7
6 6
9 10
6 7
10 165
10 10
9 9
4 9
9 9
1 1
6 8
2 9
4 6
10 10
8 9
5 9
8 8
6 10
6 6
4 6
1 6
3 7
5 9
2 8
5 6
3 5
6 9
6 8
4 7
5 8
9 9
5 7
10 10
5 8
9 10
5 5
3 8
7 10
1 1
7 8
6 ...

output:

6
9
10
10
10
7
9
9
8
9

result:

ok 10 numbers

Test #17:

score: 0
Accepted
time: 1203ms
memory: 3788kb

input:

5
1000000000 63
619459262 977043459
300995683 982228427
410548612 621234006
122929033 763884440
421486730 819706101
340188689 623537684
507398179 844353491
337184385 791508531
349294635 959826734
98096933 650360479
385580668 846357810
364950155 640902318
640098682 994083922
770432519 820631492
66011...

output:

8
17
6
40
44

result:

ok 5 number(s): "8 17 6 40 44"

Test #18:

score: -100
Time Limit Exceeded

input:

2
1000000000 1954
214176902 795098577
427614652 861416360
690405909 903037538
224031724 678866146
103017905 175158461
481177251 880591454
774838238 795104831
887429528 996876768
889351335 987035745
391908934 489988622
83670551 709453888
679022699 842242196
78153409 642923089
232797325 414737043
6804...

output:


result: