CSES - Aalto Competitive Programming 2024 - wk12 - Mon - Results
Submission details
Task:GCD and LCM
Sender:aalto2024m_002
Submission time:2024-11-25 17:24:57 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#3ACCEPTED0.00 sdetails
#40.00 sdetails
#5ACCEPTED0.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails
#160.01 sdetails
#170.00 sdetails
#180.00 sdetails
#190.00 sdetails
#200.10 sdetails
#210.00 sdetails
#220.01 sdetails
#230.00 sdetails
#240.00 sdetails
#250.01 sdetails
#260.14 sdetails
#270.00 sdetails
#280.00 sdetails
#290.00 sdetails
#300.00 sdetails
#310.01 sdetails
#320.01 sdetails
#330.00 sdetails
#340.01 sdetails
#350.00 sdetails
#360.00 sdetails
#370.00 sdetails
#380.00 sdetails
#390.00 sdetails
#400.00 sdetails
#410.00 sdetails
#420.00 sdetails
#43--details
#44--details
#45--details
#46--details
#470.00 sdetails
#480.00 sdetails
#490.00 sdetails
#500.00 sdetails
#510.00 sdetails
#520.00 sdetails
#530.00 sdetails
#540.00 sdetails
#551.09 sdetails
#561.09 sdetails
#57--details
#58--details
#59--details
#601.09 sdetails

Code

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b) {
    int c;
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}


int lcm(int a, int b, int g) {
    return (a * b) / g;
}



using namespace std;

pair <int, int> subset_mul(const vector<int>& nums, int n, int ss){
    pair<int, int> t;
    t.first = 1;
    t.second = 1;
    if (n == 0){
        return t;
    }
    vector<int> s = {0};
    int d = ss - nums[0];
    int r = nums[0];
    for (int i = 0; i <n; i++) {
        const int v = s.size();
        for (int t = 0; t < v; t++) {
            int k = s[t] * nums[i];
            if (d >= abs(ss - k)) {
                d = abs(ss - k);
                r = k;
            }
            s.push_back(k);
        }
    }
    t.first = r;
    t.second = s[size(s) - 1];
    return t;

}

vector<int> factors(int n) {
    vector<int> f;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            f.push_back(i);
            n /= i;
            while (n % i == 0) {
                f[size(f) - 1] *= i;
                n /= i;
            }
        }
    }
    return f;
}

signed main() {
    int a, b, g, l, h;
    cin >> a >> b;
    g = gcd(a, b);
    l = lcm(a, b, g);
    h = l / g;
    vector<int> f = factors(h);
    pair<int, int> t = subset_mul(f, size(f), sqrt(h));
    int x, y;
    x = g * t.first;
    y = g * (t.second / t.first);
    cout << min(x, y) << " " << max(x, y) << endl;

    return 0;
}

Test details

Test 1

Verdict:

input
3 4

correct output
3 4

user output
0 4

Test 2

Verdict:

input
1 12

correct output
3 4

user output
0 4

Test 3

Verdict: ACCEPTED

input
1 1

correct output
1 1

user output
1 1

Test 4

Verdict:

input
1 2

correct output
1 2

user output
1 1

Test 5

Verdict: ACCEPTED

input
2 2

correct output
2 2

user output
2 2

Test 6

Verdict:

input
2 1

correct output
1 2

user output
1 1

Test 7

Verdict:

input
1 6

correct output
2 3

user output
0 2

Test 8

Verdict:

input
1 9

correct output
1 9

user output
0 9

Test 9

Verdict:

input
6 1

correct output
2 3

user output
0 2

Test 10

Verdict:

input
1 1000000000

correct output
512 1953125

user output
0 512

Test 11

Verdict:

input
4 48

correct output
12 16

user output
0 16

Test 12

Verdict:

input
2 9

correct output
2 9

user output
0 2

Test 13

Verdict:

input
9 2

correct output
2 9

user output
0 2

Test 14

Verdict:

input
742625819 979252649

correct output
748840261 971126071

user output
0 3107221

Test 15

Verdict:

input
742625819 628365177

correct output
628375693 742613391

user output
0 2151

Test 16

Verdict:

input
59737016 594356392

correct output
84908056 418159112

user output
0 56

Test 17

Verdict:

input
627952539 395203065

correct output
395203065 627952539

user output
0 15

Test 18

Verdict:

input
454674271 444313814

correct output
444313814 454674271

user output
0 2

Test 19

Verdict:

input
547252636 317707623

correct output
329474572 527707899

user output
0 4

Test 20

Verdict:

input
848011418 576586631

correct output
576586631 848011418

user output
0 2

Test 21

Verdict:

input
348776064 196069730

correct output
249125760 274497622

user output
0 128

Test 22

Verdict:

input
237025447 149858613

correct output
149858613 237025447

user output
0 27

Test 23

Verdict:

input
726392299 531452772

correct output
531452772 726392299

user output
0 4

Test 24

Verdict:

input
59151261 839703616

correct output
186553977 266247488

user output
0 64

Test 25

Verdict:

input
291928593 552857636

correct output
389238124 414643227

user output
0 4

Test 26

Verdict:

input
421465106 509937555

correct output
421465106 509937555

user output
0 2

Test 27

Verdict:

input
902518094 821875115

correct output
821875115 902518094

user output
0 2

Test 28

Verdict:

input
301536505 988636664

correct output
482458408 617897915

user output
0 8

Test 29

Verdict:

input
802229414 316587683

correct output
479117567 530091086

user output
0 2

Test 30

Verdict:

input
326192670 575151518

correct output
326192670 575151518

user output
0 162

Test 31

Verdict:

input
548703061 432915082

correct output
432915082 548703061

user output
0 2

Test 32

Verdict:

input
969217649 547557803

correct output
547557803 969217649

user output
0 169

Test 33

Verdict:

input
33451382 190448754

correct output
63482918 100354146

user output
0 6

Test 34

Verdict:

input
910804372 355985662

correct output
455402186 711971324

user output
0 4

Test 35

Verdict:

input
557993572 616540429

correct output
557993572 616540429

user output
0 4

Test 36

Verdict:

input
999999999 1000000000

correct output
999999999 1000000000

user output
0 512

Test 37

Verdict:

input
999999761 1000000000

correct output
999999761 1000000000

user output
0 512

Test 38

Verdict:

input
1 1000000000

correct output
512 1953125

user output
0 512

Test 39

Verdict:

input
500000000 1000000000

correct output
500000000 1000000000

user output
500000000 500000000

Test 40

Verdict:

input
200000000 1000000000

correct output
200000000 1000000000

user output
200000000 200000000

Test 41

Verdict:

input
971959530 977699359

correct output
973924458 975726815

user output
0 34

Test 42

Verdict:

input
991437195 958491586

correct output
973924458 975726815

user output
0 34

Test 43

Verdict:

input
999999937 999999929

correct output
999999929 999999937

user output
(empty)

Test 44

Verdict:

input
999999751 999999757

correct output
999999751 999999757

user output
(empty)

Test 45

Verdict:

input
999999739 999999599

correct output
999999599 999999739

user output
(empty)

Test 46

Verdict:

input
999997357 999997403

correct output
999997357 999997403

user output
(empty)

Test 47

Verdict:

input
999999937 2

correct output
2 999999937

user output
0 2

Test 48

Verdict:

input
999999937 5

correct output
5 999999937

user output
0 5

Test 49

Verdict:

input
999999986 2

correct output
2 999999986

user output
2 2

Test 50

Verdict:

input
999999986 3

correct output
6 499999993

user output
0 2

Test 51

Verdict:

input
999999979 2

correct output
22 90909089

user output
0 2

Test 52

Verdict:

input
818181801 3

correct output
9 272727267

user output
0 9

Test 53

Verdict:

input
636363623 5

correct output
35 90909089

user output
0 5

Test 54

Verdict:

input
909090890 12

correct output
60 181818178

user output
0 4

Test 55

Verdict:

input
999999979 999999986

correct output
999999979 999999986

user output
0 2

Test 56

Verdict:

input
999999979 999999937

correct output
999999937 999999979

user output
0 11

Test 57

Verdict:

input
999999986 999999929

correct output
999999929 999999986

user output
(empty)

Test 58

Verdict:

input
999999986 999999757

correct output
999999757 999999986

user output
(empty)

Test 59

Verdict:

input
999999939 999999929

correct output
999999929 999999939

user output
(empty)

Test 60

Verdict:

input
636363623 999999929

correct output
636363623 999999929

user output
0 7