QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#310086#8148. Middle Point Graphbachbeo2007AC ✓3515ms37996kbC++2313.2kb2024-01-21 01:23:362024-01-21 01:23:37

Judging History

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

  • [2024-01-21 01:23:37]
  • 评测
  • 测评结果:AC
  • 用时:3515ms
  • 内存:37996kb
  • [2024-01-21 01:23:36]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define mpp make_pair
#define fi first
#define se second
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
const int base=101;

using uint = unsigned int;
template<uint _mod>
struct modular_fixed_base{
    static constexpr uint mod(){
        return _mod;
    }
    template<class T>
    static vector<modular_fixed_base> precalc_power(T base, int SZ){
        vector<modular_fixed_base> res(SZ + 1, 1);
        for(auto i = 1; i <= SZ; ++ i) res[i] = res[i - 1] * base;
        return res;
    }
    static vector<modular_fixed_base> _INV;
    static void precalc_inverse(int SZ){
        if(_INV.empty()) _INV.assign(2, 1);
        for(auto x = _INV.size(); x <= SZ; ++ x) _INV.push_back(_mod / x * -_INV[_mod % x]);
    }
    // _mod must be a prime
    static modular_fixed_base _primitive_root;
    static modular_fixed_base primitive_root(){
        if(_primitive_root) return _primitive_root;
        if(_mod == 2) return _primitive_root = 1;
        if(_mod == 998244353) return _primitive_root = 3;
        uint divs[20] = {};
        divs[0] = 2;
        int cnt = 1;
        uint x = (_mod - 1) / 2;
        while(x % 2 == 0) x /= 2;
        for(auto i = 3; 1LL * 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(auto g = 2; ; ++ g){
            bool ok = true;
            for(auto i = 0; i < cnt; ++ i){
                if((modular_fixed_base(g).power((_mod - 1) / divs[i])) == 1){
                    ok = false;
                    break;
                }
            }
            if(ok) return _primitive_root = g;
        }
    }
    constexpr modular_fixed_base(): data(){ }
    modular_fixed_base(const double &x){ data = normalize(llround(x)); }
    modular_fixed_base(const long double &x){ data = normalize(llround(x)); }
    template<class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base(const T &x){ data = normalize(x); }
    template<class T, typename enable_if<is_integral<T>::value>::type* = nullptr> static uint normalize(const T &x){
        int sign = x >= 0 ? 1 : -1;
        uint v =  _mod <= sign * x ? sign * x % _mod : sign * x;
        if(sign == -1 && v) v = _mod - v;
        return v;
    }
    const uint &operator()() const{ return data; }
    template<class T> operator T() const{ return data; }
    modular_fixed_base &operator+=(const modular_fixed_base &otr){ if((data += otr.data) >= _mod) data -= _mod; return *this; }
    modular_fixed_base &operator-=(const modular_fixed_base &otr){ if((data += _mod - otr.data) >= _mod) data -= _mod; return *this; }
    template<class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base &operator+=(const T &otr){ return *this += modular_fixed_base(otr); }
    template<class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base &operator-=(const T &otr){ return *this -= modular_fixed_base(otr); }
    modular_fixed_base &operator++(){ return *this += 1; }
    modular_fixed_base &operator--(){ return *this += _mod - 1; }
    modular_fixed_base operator++(int){ modular_fixed_base result(*this); *this += 1; return result; }
    modular_fixed_base operator--(int){ modular_fixed_base result(*this); *this += _mod - 1; return result; }
    modular_fixed_base operator-() const{ return modular_fixed_base(_mod - data); }
    modular_fixed_base &operator*=(const modular_fixed_base &rhs){
        data = (unsigned long long)data * rhs.data % _mod;
        return *this;
    }
    template<class T, typename enable_if<is_integral<T>::value>::type* = nullptr>
    modular_fixed_base &inplace_power(T e){
        if(e < 0) *this = 1 / *this, e = -e;
        modular_fixed_base res = 1;
        for(; e; *this *= *this, e >>= 1) if(e & 1) res *= *this;
        return *this = res;
    }
    template<class T, typename enable_if<is_integral<T>::value>::type* = nullptr>
    modular_fixed_base power(T e) const{
        return modular_fixed_base(*this).inplace_power(e);
    }
    modular_fixed_base &operator/=(const modular_fixed_base &otr){
        int a = otr.data, m = _mod, u = 0, v = 1;
        if(a < _INV.size()) return *this *= _INV[a];
        while(a){
            int t = m / a;
            m -= t * a; swap(a, m);
            u -= t * v; swap(u, v);
        }
        assert(m == 1);
        return *this *= u;
    }
    uint data;
};
template<uint _mod> vector<modular_fixed_base<_mod>> modular_fixed_base<_mod>::_INV;
template<uint _mod> modular_fixed_base<_mod> modular_fixed_base<_mod>::_primitive_root;
template<uint _mod> bool operator==(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return lhs.data == rhs.data; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> bool operator==(const modular_fixed_base<_mod> &lhs, T rhs){ return lhs == modular_fixed_base<_mod>(rhs); }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> bool operator==(T lhs, const modular_fixed_base<_mod> &rhs){ return modular_fixed_base<_mod>(lhs) == rhs; }
template<uint _mod> bool operator!=(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return !(lhs == rhs); }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> bool operator!=(const modular_fixed_base<_mod> &lhs, T rhs){ return !(lhs == rhs); }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> bool operator!=(T lhs, const modular_fixed_base<_mod> &rhs){ return !(lhs == rhs); }
template<uint _mod> bool operator<(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return lhs.data < rhs.data; }
template<uint _mod> bool operator>(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return lhs.data > rhs.data; }
template<uint _mod> bool operator<=(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return lhs.data <= rhs.data; }
template<uint _mod> bool operator>=(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return lhs.data >= rhs.data; }
template<uint _mod> modular_fixed_base<_mod> operator+(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return modular_fixed_base<_mod>(lhs) += rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator+(const modular_fixed_base<_mod> &lhs, T rhs){ return modular_fixed_base<_mod>(lhs) += rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator+(T lhs, const modular_fixed_base<_mod> &rhs){ return modular_fixed_base<_mod>(lhs) += rhs; }
template<uint _mod> modular_fixed_base<_mod> operator-(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return modular_fixed_base<_mod>(lhs) -= rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator-(const modular_fixed_base<_mod> &lhs, T rhs){ return modular_fixed_base<_mod>(lhs) -= rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator-(T lhs, const modular_fixed_base<_mod> &rhs){ return modular_fixed_base<_mod>(lhs) -= rhs; }
template<uint _mod> modular_fixed_base<_mod> operator*(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs){ return modular_fixed_base<_mod>(lhs) *= rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator*(const modular_fixed_base<_mod> &lhs, T rhs){ return modular_fixed_base<_mod>(lhs) *= rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator*(T lhs, const modular_fixed_base<_mod> &rhs){ return modular_fixed_base<_mod>(lhs) *= rhs; }
template<uint _mod> modular_fixed_base<_mod> operator/(const modular_fixed_base<_mod> &lhs, const modular_fixed_base<_mod> &rhs) { return modular_fixed_base<_mod>(lhs) /= rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator/(const modular_fixed_base<_mod> &lhs, T rhs) { return modular_fixed_base<_mod>(lhs) /= rhs; }
template<uint _mod, class T, typename enable_if<is_integral<T>::value>::type* = nullptr> modular_fixed_base<_mod> operator/(T lhs, const modular_fixed_base<_mod> &rhs) { return modular_fixed_base<_mod>(lhs) /= rhs; }
template<uint _mod> istream &operator>>(istream &in, modular_fixed_base<_mod> &number){
    long long x;
    in >> x;
    number.data = modular_fixed_base<_mod>::normalize(x);
    return in;
}
// #define _PRINT_AS_FRACTION
template<uint _mod> ostream &operator<<(ostream &out, const modular_fixed_base<_mod> &number){
#ifdef LOCAL
#ifdef _PRINT_AS_FRACTION
    out << number();
    cerr << "(";
    for(auto d = 1; ; ++ d){
        if((number * d).data <= 1000000){
            cerr << (number * d).data << "/" << d;
            break;
        }
        else if((-number * d).data <= 1000000){
            cerr << "-" << (-number * d).data << "/" << d;
            break;
        }
    }
    cerr << ")";
    return out;
#else
    return out << number();
#endif
#else
    return out << number();
#endif
}
#undef _PRINT_AS_FRACTION

const uint mod = 1e9 + 7; // 1000000007
// const uint mod = (119 << 23) + 1; // 998244353
// const uint mod = 1e9 + 9; // 1000000009
using modular = modular_fixed_base<mod>;

// O(n + m * sqrt(m)) for graphs without loops or multiedges
template<class T>
T count_4_cycles(int n, const vector<array<int, 2>> &edge){
    int m = (int)edge.size();
    vector<int> deg(n), order, pos(n);
    vector<vector<int>> appear(m + 1), adj(n);
    for(auto [u, v]: edge) ++ deg[u], ++ deg[v];
    for(auto u = 0; u < n; ++ u) appear[deg[u]].push_back(u);
    for(auto d = m; d >= 0; -- d) order.insert(order.end(), appear[d].begin(), appear[d].end());
    for(auto i = 0; i < n; ++ i) pos[order[i]] = i;
    for(auto i = 0; i < m; ++ i){
        int u = pos[edge[i][0]], v = pos[edge[i][1]];
        adj[u].push_back(v), adj[v].push_back(u);
    }
    T res = 0;
    vector<int> cnt(n);
    for(auto u = 0; u < n; ++ u){
        for(auto v: adj[u]) if(u < v) for(auto w: adj[v]) if(u < w) cnt[w] = 0;
        for(auto v: adj[u]) if(u < v) for(auto w: adj[v]) if(u < w) res += cnt[w] ++;
    }
    return res;
}
const int Max=1000;
template<class T>
T count_3_cycles(int n, const vector<array<int, 2>> &edge){
    vector<vector<int>> adj(n);
    vector<int> deg(n),num(n);
    for(auto [u,v]:edge){
        deg[u]++;deg[v]++;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    T res = 0;
    for(auto [u,v]:edge){
        if(deg[u]<=Max && deg[v]<=Max){
            for(int x:adj[u]) num[x]++;
            for(int x:adj[v]) if(num[x] && deg[x]<=Max) res+=1;
            for(int x:adj[u]) num[x]--;
        }
    }
    res/=3;
    for(int i=0;i<n;i++){
        if(deg[i]<=Max) continue;
        for(int x:adj[i]) num[x]++;
        for(auto [u,v]:edge){
            if((u<=i && deg[u]>Max) || (v<=i && deg[v]>Max)) continue;
            if(num[u] && num[v]) res+=1;
        }
        for(int x:adj[i]) num[x]--;
    }
    return res;
}

int deg[maxn];

void solve(){
    int n,m;cin >> n >> m;
    for(int i=1;i<=n;i++) deg[i]=0;
    vector<array<int,2>> edge;
    for(int i=1;i<=m;i++){
        int u,v;cin >> u >> v;
        deg[u]++;deg[v]++;
        edge.push_back({u-1,v-1});
    }
    modular res=modular(m)*modular(n+m-3);
    for(int i=1;i<=n;i++) res+=modular(deg[i])*modular((deg[i]-1))/2;
    res+=count_4_cycles<modular>(n,edge);
    res+=count_3_cycles<modular>(n,edge)*3;
    cout << res << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;cin >> test;
    while(test--) solve();
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

input:

3

7 18
2 1
2 3
3 4
2 5
6 4
7 5
6 5
3 1
1 5
1 7
7 3
2 6
2 7
4 5
5 3
4 2
6 7
6 3

5 7
1 2
2 3
4 2
5 1
1 4
3 5
3 1

1 0

output:

593
88
0

result:

ok 3 number(s): "593 88 0"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

10

2 1
2 1

1 0

3 3
2 1
1 3
3 2

2 1
2 1

2 1
2 1

1 0

2 1
2 1

2 1
1 2

1 0

4 6
1 2
2 3
1 4
1 3
2 4
3 4

output:

0
0
15
0
0
0
0
0
0
69

result:

ok 10 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

10

1 0

1 0

2 1
2 1

5 6
1 2
2 3
4 1
1 5
3 1
5 4

3 3
1 2
3 1
3 2

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

1 0

3 3
1 2
2 3
3 1

4 6
2 1
1 3
4 3
2 4
2 3
1 4

1 0

output:

0
0
0
64
15
122
0
15
69
0

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

1

50 50
2 1
2 3
4 1
1 5
1 6
1 7
2 8
9 2
10 5
2 11
7 12
12 13
2 14
10 15
16 2
12 17
18 3
18 19
20 16
1 21
12 22
23 18
24 16
25 5
8 26
27 10
28 12
21 29
30 27
27 31
32 13
33 32
14 34
35 18
33 36
37 30
38 16
17 39
23 40
8 41
35 42
5 43
32 44
32 45
46 39
47 3
48 11
49 18
39 50
5 45

output:

4954

result:

ok 1 number(s): "4954"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

1

30 50
2 1
2 3
3 4
5 4
2 6
7 5
4 8
3 9
9 10
8 11
4 12
13 6
14 8
15 12
16 10
5 17
2 18
19 16
6 20
8 21
22 21
7 23
15 24
16 25
13 26
20 27
16 28
29 19
15 30
18 10
17 7
16 13
18 19
15 20
18 28
28 15
21 28
21 3
12 23
4 16
27 26
19 9
2 28
10 7
25 9
5 22
15 22
4 27
10 24
16 12

output:

4025

result:

ok 1 number(s): "4025"

Test #6:

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

input:

1

1000 1000
2 1
3 2
2 4
5 2
4 6
6 7
5 8
9 5
1 10
7 11
12 1
4 13
10 14
15 4
16 5
11 17
3 18
9 19
4 20
21 14
22 11
23 9
2 24
25 7
22 26
21 27
28 14
29 23
30 26
31 11
8 32
33 6
10 34
35 33
21 36
37 7
38 1
39 32
40 16
41 28
40 42
43 20
43 44
45 12
14 46
47 3
48 45
49 13
38 50
51 3
52 46
53 49
54 29
55 ...

output:

1999026

result:

ok 1 number(s): "1999026"

Test #7:

score: 0
Accepted
time: 1ms
memory: 3660kb

input:

2

465 465
2 1
2 3
4 2
4 5
6 4
7 2
8 4
9 7
1 10
5 11
12 10
13 7
7 14
15 3
4 16
6 17
18 6
17 19
20 2
5 21
15 22
17 23
24 12
2 25
3 26
11 27
7 28
6 29
29 30
19 31
32 15
11 33
34 33
4 35
8 36
37 16
16 38
15 39
40 8
29 41
42 8
20 43
44 42
45 23
35 46
31 47
45 48
49 11
39 50
51 18
52 39
52 53
26 54
55 49...

output:

431981
571965

result:

ok 2 number(s): "431981 571965"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3592kb

input:

10

38 38
1 2
3 1
4 1
4 5
2 6
7 2
2 8
6 9
4 10
11 1
4 12
11 13
5 14
13 15
7 16
13 17
18 6
19 4
20 11
11 21
18 22
3 23
21 24
12 25
6 26
27 12
28 14
29 14
30 16
31 6
13 32
10 33
34 28
28 35
26 36
15 37
38 4
18 26

34 33
1 2
3 1
3 4
2 5
6 4
6 7
3 8
9 7
4 10
3 11
12 8
5 13
14 10
4 15
12 16
5 17
18 7
19 ...

output:

2848
2167
207687
3185
2551
61432
0
13768
127716
619

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 225ms
memory: 37996kb

input:

1

200000 500000
1 2
1 3
1 4
1 9
10 1
1 15
1 45
1 121
580 1
859 1
47503 1
1 50314
1 60144
62615 1
112616 1
1 141630
1 172171
2 6
2 366
2 534
2 2313
2 3517
2 3690
4649 2
7189 2
2 37784
2 45766
2 53945
5 3
3 8
16 3
3 33
3 148
155 3
3 189
697 3
3746 3
3 5645
3 29590
46100 3
3 132857
3 175635
26 4
29 4
...

output:

1029064

result:

ok 1 number(s): "1029064"

Test #10:

score: 0
Accepted
time: 189ms
memory: 29244kb

input:

2

142566 381939
1 2
8 1
1 10
1 11
1 15
1 42
1 144
1 388
554 1
909 1
15546 1
38439 1
1 79354
1 117244
119416 1
3 2
2 4
2 6
7 2
2 12
18 2
2 366
2 372
1946 2
8509 2
8813 2
2 11657
19598 2
2 34365
3 5
34 3
3 94
103 3
596 3
1778 3
3 1958
3 8965
13289 3
31676 3
36965 3
37538 3
90811 3
3 125297
9 4
21 4
4...

output:

329860510
719239121

result:

ok 2 number(s): "329860510 719239121"

Test #11:

score: 0
Accepted
time: 169ms
memory: 10328kb

input:

10

9129 42610
1 2
1 3
4 1
5 1
18 1
30 1
1 69
1 789
904 1
1 1862
1 4758
7 2
2 10
2 17
2 661
1128 2
2242 2
2 2661
8259 2
8509 2
3 29
79 3
3 86
3 150
3 400
473 3
477 3
3 2225
3 3417
3 5843
4 12
4 14
37 4
4 122
4 153
245 4
255 4
354 4
4 527
1159 4
4 2614
4 3089
4 3854
4399 4
4 5379
4 6117
6413 4
4 7925...

output:

204908516
71692365
172496393
280630811
661096409
1029943
834960655
776344491
64274552
346772110

result:

ok 10 numbers

Test #12:

score: 0
Accepted
time: 143ms
memory: 8168kb

input:

20

2604 11844
1 2
3 1
4 1
108 1
124 1
1 349
1 1277
1 1415
1 1517
1706 1
2365 1
1 2480
5 2
2 6
2 14
2 18
126 2
170 2
2 189
2 280
2 418
578 2
902 2
2 1626
2426 2
60 3
3 76
351 3
3 640
3 1248
7 4
9 4
4 10
4 42
4 110
2251 4
8 5
12 5
17 5
5 183
490 5
637 5
692 5
776 5
5 1284
2087 5
2340 5
2370 5
2455 5
...

output:

171207587
591910409
655247056
10725
230460448
50006952
942410958
801609893
472450535
100115090
590130419
133326603
280253593
11942031
61041524
315965858
19957752
307791784
395041475
10367647

result:

ok 20 numbers

Test #13:

score: 0
Accepted
time: 158ms
memory: 4832kb

input:

100

342 5076
2 1
3 2
3 4
5 3
6 5
2 7
8 5
9 3
2 10
10 11
12 7
1 13
10 14
2 15
13 16
8 17
18 15
8 19
9 20
21 2
9 22
23 3
1 24
25 3
1 26
27 17
15 28
29 19
30 28
31 9
32 4
9 33
34 32
35 9
36 35
32 37
38 31
12 39
24 40
41 19
28 42
43 5
44 24
12 45
24 46
42 47
48 6
39 49
6 50
51 12
52 51
53 44
42 54
55 4...

output:

27746759
50658517
10683786
24139720
25932859
47565852
350610
11486775
1319626
12904287
14148993
47015672
135120800
161318098
467490
12777493
6450863
62320822
20009150
334697950
195220423
56701910
29206042
7394506
1413245
19254945
20145190
14605944
4172671
494307456
4613126
4221870
1420419
29162821
7...

result:

ok 100 numbers

Test #14:

score: 0
Accepted
time: 161ms
memory: 4396kb

input:

200

3492 4712
1 2
3 1
6 1
1 8
23 1
28 1
35 1
89 1
1 153
343 1
487 1
1 611
1852 1
2 5
7 2
2 27
33 2
2 39
132 2
2 217
2 364
2 866
2 1154
2914 2
3 4
9 3
3 16
3 471
546 3
1777 3
3 1987
2540 3
12 4
17 4
4 22
45 4
4 50
70 4
495 4
4 524
13 5
5 21
641 5
5 2283
3156 5
11 6
15 6
6 20
6 138
6 543
7 162
7 399
...

output:

38655363
1017898
3567787
1321355
19004105
42329957
28643577
21376173
18547078
10433752
39780
33142803
621975
4919571
9899302
1993502
4281270
9585129
5774276
722395
29367261
6297777
7238668
1097217
10514340
6239585
814133
21693865
60622602
20043975
3728795
3690
328471
9289139
2691351
13402
21489221
4...

result:

ok 200 numbers

Test #15:

score: 0
Accepted
time: 153ms
memory: 3888kb

input:

1000

242 624
2 1
1 3
1 4
4 5
4 6
1 7
2 8
9 7
10 4
11 9
12 6
10 13
9 14
11 15
16 1
8 17
3 18
19 5
20 12
3 21
22 15
23 22
1 24
25 22
26 14
27 17
22 28
29 10
3 30
31 30
22 32
33 22
34 3
23 35
8 36
34 37
38 6
39 6
36 40
41 24
42 13
38 43
38 44
45 31
3 46
7 47
48 26
44 49
50 6
51 8
12 52
4 53
23 54
13 5...

output:

541912
509357
55819
187902
98340
156244
366366
10725
693
2130479
69305
1662331
306918
49195
243743
519758
54684
267804
0
154013
9860
625485
55900
7755
350818
764595
1250337
13067
440600
2394
271649
326377
32180
568235
43508
123292
225968
12422
340577
497708
1955209
10439
116167
88379
31620
89884
178...

result:

ok 1000 numbers

Test #16:

score: 0
Accepted
time: 145ms
memory: 3816kb

input:

2000

12 66
1 2
1 3
4 1
5 1
6 1
5 7
7 8
9 8
3 10
11 9
12 6
7 12
4 9
2 10
11 8
1 9
2 11
8 2
4 3
11 10
2 7
2 9
3 7
5 10
8 5
12 8
9 6
1 11
10 8
11 7
6 4
6 5
10 7
4 2
4 7
11 12
9 10
7 6
9 12
6 10
11 3
12 10
4 5
11 5
12 4
2 12
5 9
12 3
8 3
2 6
7 1
6 8
1 12
7 9
8 4
6 11
8 1
3 5
3 6
3 9
11 4
3 2
1 10
10 4
...

output:

7755
448
12168
767060
24305
106260
378278
102105
18092
231493
49525
19072
251
7153
39571
13041
261908
4913
712783
7065
58838
404651
32739
2394
0
169212
18999
87040
32950
61917
288935
3274
86607
12016
1255
22553
131906
37114
127868
5604
70109
117728
24780
334135
55381
512084
47103
58577
42172
5634
14...

result:

ok 2000 numbers

Test #17:

score: 0
Accepted
time: 130ms
memory: 3908kb

input:

10000

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

11 55
1 2
2 3
4 3
5 1
5 6
7 3
8 4
1 9
5 10
9 11
11 1
2 7
2 6
7 11
5 ...

output:

2972
5445
4206
69
19052
1899
23656
1040
11373
6179
15
41337
840
840
69
2394
2806
724
0
2126
15
876
1269
1281
10790
297
1300
1026
10098
0
6438
840
195
69
2146
0
2325
3782
6490
840
840
19124
270
1760
22373
995
1466
435
1470
113
5039
777
3461
9593
8651
457
4143
5265
10725
396
4716
45
1836
3598
435
1470...

result:

ok 10000 numbers

Test #18:

score: 0
Accepted
time: 3515ms
memory: 23188kb

input:

1

1000 499500
52 697
781 742
301 407
36 931
460 749
986 912
376 404
463 618
80 297
974 429
829 470
826 952
3 455
207 396
917 627
280 272
769 209
938 37
753 174
411 134
904 115
207 567
297 807
273 627
658 859
556 696
729 813
886 813
692 998
43 614
468 441
326 702
287 162
930 1000
905 629
526 206
86 ...

output:

246625125

result:

ok 1 number(s): "246625125"

Test #19:

score: 0
Accepted
time: 896ms
memory: 32908kb

input:

1

100000 500000
2209 34206
1944 19358
23598 51829
63541 70843
21139 96565
13029 43066
22246 49561
92241 98233
92260 23681
27750 49786
88490 87218
89973 52483
82685 90036
38099 65470
8067 31922
31802 30874
42728 77117
91975 1928
92346 73802
72378 20638
69198 39151
14265 74104
4697 2506
5196 99602
23...

output:

742969024

result:

ok 1 number(s): "742969024"

Test #20:

score: 0
Accepted
time: 1501ms
memory: 31152kb

input:

1

100000 500000
43432 62093
91287 71798
90007 35557
47284 48843
97621 23840
29292 16347
34888 85828
5613 86342
43335 13417
86876 33408
36224 71870
54350 43055
38323 45413
2381 23696
65973 84499
57177 29683
10414 21937
4612 50234
87387 26141
66133 84702
57804 57706
93606 61130
57255 61915
7686 87550...

output:

935092768

result:

ok 1 number(s): "935092768"

Test #21:

score: 0
Accepted
time: 2791ms
memory: 32568kb

input:

1

100000 500000
44547 48301
9608 16597
22027 78003
27167 62437
12347 59691
89469 56645
81810 11546
21396 74363
48211 95880
46264 8881
25830 42304
18402 62262
18805 54355
84208 66811
74672 78293
54114 81750
86249 86111
25215 85890
53113 75947
49294 56350
88057 19643
59805 58826
92298 61875
56382 822...

output:

220868041

result:

ok 1 number(s): "220868041"

Test #22:

score: 0
Accepted
time: 2822ms
memory: 31180kb

input:

1

100000 500000
96791 13976
44118 17547
78496 30994
97506 88040
8906 51005
77021 74888
97902 48162
17229 18353
51325 97122
3306 59388
7577 10449
47744 11670
84887 34741
19536 31938
81636 81995
17614 5844
24509 37955
86244 12119
96693 82879
50606 40809
70451 60920
39773 58394
84881 44377
80084 69361...

output:

925493025

result:

ok 1 number(s): "925493025"

Test #23:

score: 0
Accepted
time: 2701ms
memory: 30928kb

input:

1

100000 500000
35359 1034
11810 16108
83818 78042
41121 13251
34512 90055
54673 50443
51144 31693
40115 85912
47296 53145
22814 75633
64983 66572
53790 38513
31620 63451
32431 46633
53421 77554
7078 73115
75089 42732
33769 87616
17695 41885
48626 51844
22908 65001
94607 3429
24354 30538
39205 4331...

output:

839187312

result:

ok 1 number(s): "839187312"

Test #24:

score: 0
Accepted
time: 2559ms
memory: 30952kb

input:

1

100000 500000
5955 90429
40833 94860
48709 86793
19112 98398
30713 70527
58292 7578
76051 3635
5893 14991
96157 53776
493 78081
94963 66483
52562 85192
48453 4334
69584 76783
62968 25510
46645 19189
65189 88310
42884 4751
63801 66282
32178 93828
96244 48805
22796 63248
42314 88251
9775 73058
7264...

output:

143933648

result:

ok 1 number(s): "143933648"

Test #25:

score: 0
Accepted
time: 2221ms
memory: 30432kb

input:

1

100000 500000
57678 58079
18086 82083
74301 18654
49578 57999
63623 12201
15376 82690
54698 50641
40422 48978
83654 25805
34688 24278
95489 20118
52725 7435
37 81356
90624 51727
93309 69647
82272 41961
81755 8038
95800 26175
94965 21244
99311 97117
73955 53726
55634 26645
11715 10526
99693 31226
...

output:

725291929

result:

ok 1 number(s): "725291929"

Test #26:

score: 0
Accepted
time: 2028ms
memory: 30500kb

input:

1

100000 500000
21374 19010
41479 86322
75621 70857
27899 51043
47155 49678
62463 72682
20160 87284
11979 832
98088 63461
3485 31006
18604 57934
56153 97956
52048 70496
1028 39158
16731 38929
79976 79098
18137 60537
60724 60571
91996 50261
65913 34089
47735 75976
72462 18871
94946 98869
60620 69340...

output:

505321930

result:

ok 1 number(s): "505321930"

Test #27:

score: 0
Accepted
time: 1896ms
memory: 30384kb

input:

1

100000 500000
29154 2904
15325 10735
50873 49136
72195 38289
22498 13916
95488 4953
22121 84204
54737 32603
57308 86164
89913 31597
54638 73196
85595 88712
69432 81296
58049 46603
89940 7488
80856 83640
91809 16514
46257 9845
20226 98011
8130 70925
9726 32954
6595 69837
70401 77134
45938 82311
72...

output:

809243221

result:

ok 1 number(s): "809243221"

Extra Test:

score: 0
Extra Test Passed