ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 1511-B, *1100
    코드포스 2021. 8. 8. 14:59
     

    Problem - 1511B - Codeforces

     

    codeforces.com

    문제

    • $\mathrm{gcd(a,\ b)}$가 $c$ 자리수이고 각각의 자리수가 $a,\ b(1\leq a,\ b \leq 9)$인 두 수 A, B를 구하라

     

    $O(1)$

    $c$ 자리의 소수를 $\mathrm{gcd(A,\ B)}$라고 두고 A 와 B 를 만든다
    $\mathrm{(A,\ B)}$가 변하면 안되므로 $\mathrm{(A,\ B)}$에 서로다른 소수를 곱하여 A 와 B 를 만든다

    Claim
    각각의 자리수가 $a,\ b(1\leq a,\ b \leq 9)$인 두 수 A, B 에 대해
    두 수의 최고자리수가 모두 3 이하면 AB는 a+b-1 자리수이다

    $\because$
    AB의 자릿수는 A와 B의 최고자릿수의 곱만 보면 된다
    Let
    A $\rightarrow {a}'\cdot10^{a-1}$,
    B $\rightarrow {b}'\cdot10^{b-1}$

    AB $\rightarrow {a}'{b}'\cdot10^{a+b-2}$, ${a}'{b}'\leq 9$
    따라서 AB는 a+b-1 자리수이다□

    이제 최고자리수가 3 이하인, 1~9 자리의 소수를 구하자

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    #include <bits/stdc++.h>
    #define endl "\n"
    #define loop(i, n) for(int i = 1; i <= n; i++)
    using namespace std;
     
    int find;
     
    bool isprime(int p, int& find)
    {
        bool flag = true;
        for(int i = 3; i*<= p; i+=2){
            if(p%i == 0) flag = false;
        }
        if(flag){
            cout << p << endl;
            find++;
            return true;
        }
        else return false;
    }
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        int p;
        for(int i = 1; i <= 8; i++){
            p = pow(10, i)+1;
            int find = 0;
            while(!isprime(p, find) or find < 2) {
                p += 2;
            }
        }
     
     
        return 0;
    11 13 101 103 1009 1013 10007 10009 100003 100019 1000003 1000033 10000019 10000079 100000007 100000037 Process finished with exit code 0

    이를 이용해서 코드를 구성하면 된다

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    #include <bits/stdc++.h>
    #define endl "\n"
    #define loop(i, n) for(int i = 1; i <= n; i++)
    using namespace std;
     
    int a, b, c;
    map<intvector<int> > m = {
            {0, {23}},
            {1, {1113}},
            {2, {101103}},
            {3, {10091013}},
            {4, {1000710009}},
            {5, {100003100019}},
            {6, {10000031000033}},
            {7, {1000001910000079}},
            {8, {100000007100000037}}
    };
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        int t;
        cin >> t;
        while(t--){
            cin >> a >> b >> c;
            cout << m[c-1][0]*m[a-c][0<< ' ' << m[c-1][0]*m[b-c][1<< endl;
        }
     
        return 0;

     

    $O(1)$

    $111\cdot \cdot \cdot 111$와 $100\cdot \cdot \cdot 000$은 서로소임을 이용한다

    $$\begin{align*}
    &gcd(A,\ B)=10^{c-1}\\
    &\text{A}=1\underset{a-c}{\underbrace{00..00}}\underset{c-1}{\underbrace{00..00}}\\
    &\text{B}=1\underset{b-c}{\underbrace{11..11}}\underset{c-1}{\underbrace{00..00}}
    \end{align*}$$

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    #include <bits/stdc++.h>
    #define endl "\n"
    #define loop(i, n) for(int i = 1; i <= n; i++)
    using namespace std;
     
    int a, b, c;
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        int t;
        cin >> t;
        while(t--){
            cin >> a >> b >> c;
            cout << 1;
            loop(i, a-1cout << 0;
            cout << ' ';
            loop(i, b-c+1cout << 1;
            loop(i, c-1cout << 0;
            cout << endl;
        }
     
        return 0;

    '코드포스' 카테고리의 다른 글

    1512-C, *1200  (0) 2021.08.08
    1520-D, *1200  (0) 2021.08.08
    1454-D, *1300  (0) 2021.08.07
    1521-B, *1300  (0) 2021.08.01
    1534-C, *1300  (0) 2021.08.01

    댓글

Designed by Tistory.