CSES - Aalto Competitive Programming 2024 - wk12 - Mon - Results
Submission details
Task:GCD and LCM
Sender:aalto2024m_002
Submission time:2024-11-25 17:56:28 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.01 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.11 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.01 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.01 sdetails
#26ACCEPTED0.15 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.01 sdetails
#32ACCEPTED0.01 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.01 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#43--details
#44--details
#45--details
#46--details
#47ACCEPTED0.00 sdetails
#48ACCEPTED0.00 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.01 sdetails
#51ACCEPTED0.00 sdetails
#52ACCEPTED0.00 sdetails
#53ACCEPTED0.01 sdetails
#54ACCEPTED0.00 sdetails
#55ACCEPTED1.21 sdetails
#56ACCEPTED1.21 sdetails
#57--details
#58--details
#59--details
#60ACCEPTED1.21 sdetails

Code

#include <iostream>
#include <vector>
#include <cmath>
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;
    int d = ss - nums[0];
    int r = nums[0];
    int m = 1;
    if (n == 0){
        return t;
    }
    for (int i = 1; i < (1ll<<n); i++) {
        int curr=1;
        for (int j = 0; j < n; j++) {
            if((1ll<<j)&i) curr*=nums[j];
        }
        if (d >= abs(ss - curr)) {
            d = abs(ss - curr);
            r = curr;
        }
        m = max(m, curr);
    }
    t.first = r;
    t.second = m;
    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[f.size() - 1] *= i;
                n /= i;
            }
        }
    }
    if (n != 1) {
        f.push_back(n);
    }
    // cout << "hehe" << endl;
    // for (int i = 0; i < f.size(); i++) {
    //     cout << f[i] << " ";
    // }
    // cout << "hehe" <<  endl;
    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, f.size(), sqrt(h));
    int x, y;
    // cout << g << endl;
    // cout << l << endl;
    // cout << t.first << " " << t.second << endl;
    x = g * t.first;
    y = g * (t.second / t.first);
    // cout << x << " " << y << endl;
    cout << min(x, y) << " " << max(x, y) << endl;

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
3 4

correct output
3 4

user output
3 4

Test 2

Verdict: ACCEPTED

input
1 12

correct output
3 4

user output
3 4

Test 3

Verdict: ACCEPTED

input
1 1

correct output
1 1

user output
1 1

Test 4

Verdict: ACCEPTED

input
1 2

correct output
1 2

user output
1 2

Test 5

Verdict: ACCEPTED

input
2 2

correct output
2 2

user output
2 2

Test 6

Verdict: ACCEPTED

input
2 1

correct output
1 2

user output
1 2

Test 7

Verdict: ACCEPTED

input
1 6

correct output
2 3

user output
2 3

Test 8

Verdict: ACCEPTED

input
1 9

correct output
1 9

user output
1 9

Test 9

Verdict: ACCEPTED

input
6 1

correct output
2 3

user output
2 3

Test 10

Verdict: ACCEPTED

input
1 1000000000

correct output
512 1953125

user output
512 1953125

Test 11

Verdict: ACCEPTED

input
4 48

correct output
12 16

user output
12 16

Test 12

Verdict: ACCEPTED

input
2 9

correct output
2 9

user output
2 9

Test 13

Verdict: ACCEPTED

input
9 2

correct output
2 9

user output
2 9

Test 14

Verdict: ACCEPTED

input
742625819 979252649

correct output
748840261 971126071

user output
748840261 971126071

Test 15

Verdict: ACCEPTED

input
742625819 628365177

correct output
628375693 742613391

user output
628375693 742613391

Test 16

Verdict: ACCEPTED

input
59737016 594356392

correct output
84908056 418159112

user output
84908056 418159112

Test 17

Verdict: ACCEPTED

input
627952539 395203065

correct output
395203065 627952539

user output
395203065 627952539

Test 18

Verdict: ACCEPTED

input
454674271 444313814

correct output
444313814 454674271

user output
444313814 454674271

Test 19

Verdict: ACCEPTED

input
547252636 317707623

correct output
329474572 527707899

user output
329474572 527707899

Test 20

Verdict: ACCEPTED

input
848011418 576586631

correct output
576586631 848011418

user output
576586631 848011418

Test 21

Verdict: ACCEPTED

input
348776064 196069730

correct output
249125760 274497622

user output
249125760 274497622

Test 22

Verdict: ACCEPTED

input
237025447 149858613

correct output
149858613 237025447

user output
149858613 237025447

Test 23

Verdict: ACCEPTED

input
726392299 531452772

correct output
531452772 726392299

user output
531452772 726392299

Test 24

Verdict: ACCEPTED

input
59151261 839703616

correct output
186553977 266247488

user output
186553977 266247488

Test 25

Verdict: ACCEPTED

input
291928593 552857636

correct output
389238124 414643227

user output
389238124 414643227

Test 26

Verdict: ACCEPTED

input
421465106 509937555

correct output
421465106 509937555

user output
421465106 509937555

Test 27

Verdict: ACCEPTED

input
902518094 821875115

correct output
821875115 902518094

user output
821875115 902518094

Test 28

Verdict: ACCEPTED

input
301536505 988636664

correct output
482458408 617897915

user output
482458408 617897915

Test 29

Verdict: ACCEPTED

input
802229414 316587683

correct output
479117567 530091086

user output
479117567 530091086

Test 30

Verdict: ACCEPTED

input
326192670 575151518

correct output
326192670 575151518

user output
326192670 575151518

Test 31

Verdict: ACCEPTED

input
548703061 432915082

correct output
432915082 548703061

user output
432915082 548703061

Test 32

Verdict: ACCEPTED

input
969217649 547557803

correct output
547557803 969217649

user output
547557803 969217649

Test 33

Verdict: ACCEPTED

input
33451382 190448754

correct output
63482918 100354146

user output
63482918 100354146

Test 34

Verdict: ACCEPTED

input
910804372 355985662

correct output
455402186 711971324

user output
455402186 711971324

Test 35

Verdict: ACCEPTED

input
557993572 616540429

correct output
557993572 616540429

user output
557993572 616540429

Test 36

Verdict: ACCEPTED

input
999999999 1000000000

correct output
999999999 1000000000

user output
999999999 1000000000

Test 37

Verdict: ACCEPTED

input
999999761 1000000000

correct output
999999761 1000000000

user output
999999761 1000000000

Test 38

Verdict: ACCEPTED

input
1 1000000000

correct output
512 1953125

user output
512 1953125

Test 39

Verdict: ACCEPTED

input
500000000 1000000000

correct output
500000000 1000000000

user output
500000000 1000000000

Test 40

Verdict: ACCEPTED

input
200000000 1000000000

correct output
200000000 1000000000

user output
200000000 1000000000

Test 41

Verdict: ACCEPTED

input
971959530 977699359

correct output
973924458 975726815

user output
973924458 975726815

Test 42

Verdict: ACCEPTED

input
991437195 958491586

correct output
973924458 975726815

user output
973924458 975726815

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: ACCEPTED

input
999999937 2

correct output
2 999999937

user output
2 999999937

Test 48

Verdict: ACCEPTED

input
999999937 5

correct output
5 999999937

user output
5 999999937

Test 49

Verdict: ACCEPTED

input
999999986 2

correct output
2 999999986

user output
2 999999986

Test 50

Verdict: ACCEPTED

input
999999986 3

correct output
6 499999993

user output
6 499999993

Test 51

Verdict: ACCEPTED

input
999999979 2

correct output
22 90909089

user output
22 90909089

Test 52

Verdict: ACCEPTED

input
818181801 3

correct output
9 272727267

user output
9 272727267

Test 53

Verdict: ACCEPTED

input
636363623 5

correct output
35 90909089

user output
35 90909089

Test 54

Verdict: ACCEPTED

input
909090890 12

correct output
60 181818178

user output
60 181818178

Test 55

Verdict: ACCEPTED

input
999999979 999999986

correct output
999999979 999999986

user output
999999979 999999986

Test 56

Verdict: ACCEPTED

input
999999979 999999937

correct output
999999937 999999979

user output
999999937 999999979

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: ACCEPTED

input
636363623 999999929

correct output
636363623 999999929

user output
636363623 999999929