728x90

 

import java.io.*;
import java.util.*;

public class Main {

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); //선언

    public static void main(String[] args) throws IOException {
        String s= bf.readLine();
        String parts[] = s.split(" ");

        int n = Integer.parseInt(parts[0]);
        int k = Integer.parseInt(parts[1]);

        if(n==k)
        {
            System.out.println(n);
            System.out.println(n);
            return;
        }

        int big;
        int small;
        if(n>k)
        {
            big = n;
            small = k;
        }
        else {
            big = k;
            small = n;
        }

        int gcd = big*small;

        int x;
        while (small != 0)
        {
            x = big%small;
            big = small;
            small = x;
            gcd = big;
        }
        System.out.println(gcd);

        System.out.println(n*k/gcd);


    }
}
728x90

'알고리즘' 카테고리의 다른 글

백준 알고리즘 5347  (2) 2024.03.29
백준 알고리즘 9934  (0) 2024.03.29
백준 알고리즘 2075  (0) 2024.03.29
백준 알고리즘 2800  (0) 2024.03.29
백준 알고리즘 10828  (0) 2024.03.29
728x90

import java.io.*;
import java.util.*;

class pairs
{

    pairs(int i, int ii)
    {
        first = i;
        second = ii;
    }
    public int first;
    public int second;
}

public class Main {
    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); //선언

    static int arr[] = new int[10001];
    static int size;
    static ArrayList<Integer>[] tree;
    public static void main(String[] args) throws IOException {

        String n = bf.readLine();
        size  = Integer.parseInt(n);

        String n1 = bf.readLine();
        String[] parts = n1.split(" ");

        for (int j = 0; j < parts.length; j++) {
            arr[j] = Integer.parseInt(parts[j]);
        }

        tree = new ArrayList[size+1];

        for (int i = 0; i < size; i++) {
            tree[i] = new ArrayList<>();
        }

        search(0,0,parts.length-1);

        for (int i = 0; i < size; i++) {
            Iterator<Integer> iterator = tree[i].iterator();
            while (iterator.hasNext())
            {
                System.out.print(iterator.next()+" ");
            }
            System.out.println();
        }

    }


    public static void search(int level, int start, int end)
    {
        if(level == size)
            return;

        int mid = (start + end)/2;

        tree[level].add(arr[mid]);

        search(level+1, start, mid-1);
        search(level + 1, mid+1, end);
    }
}
728x90

'알고리즘' 카테고리의 다른 글

백준 알고리즘 5347  (2) 2024.03.29
백준 알고리즘 2609  (1) 2024.03.29
백준 알고리즘 2075  (0) 2024.03.29
백준 알고리즘 2800  (0) 2024.03.29
백준 알고리즘 10828  (0) 2024.03.29
728x90

 

import java.io.*;
import java.util.*;
public class Main {
    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); //선언
    static String s;

    static Set<String> set = new HashSet<>();

    public static void main(String[] args) throws IOException
    {
        s = bf.readLine();
        for (int i = 0; i < s.length(); i++) {
            dfs(i,i,String.valueOf(s.charAt(i)), "", "");
        }
        System.out.println(set.size());
    }

    public static void dfs(int left, int right, String newWay, String cur, String result)
    {
        result = result + cur + newWay;
        boolean canGoLeft = left - 1 < 0 ? false:true;
        boolean canGoRight = right + 1 > s.length()-1 ? false:true;
        if( !canGoLeft&&!canGoRight)
        {
            //System.out.println(result);
            set.add(result);

            return;
        }
        if(canGoLeft)
        {
            String news = String.valueOf(s.charAt(left-1));
            dfs(left - 1,right, news, cur + newWay, result);
        }
        if(canGoRight)
        {
            String news = String.valueOf(s.charAt(right+1));
            dfs(left,right+1, news,cur + newWay,result);
        }


    }
}
728x90

'JAVA' 카테고리의 다른 글

JAVA TIL - 04 Java.base 모듈 - java.lang  (0) 2024.03.15
JAVA TIL - 03 JVM  (0) 2024.03.12
JAVA TIL - 02 abstract 추상 메서드/클래스  (0) 2024.03.12
JAVA TIL - 01 다형성  (0) 2024.03.12

+ Recent posts