U E D R , A S I H C RSS

1R/2016_09_15



1. 오늘의 문제

2. 참가자

  • 미시행

3. 코드

3.1. 15이원준

#include<iostream>
using namespace std;

int checker(int f, int s){
  int answer;
  for(int i = 1; i*i<= f; i++){
    if(f%i == 0 && s%i == 0){
      answer = i;
    }
  }
  return answer;
}

int main(){
  int L,M;
  scanf("%d %d", &L, &M);
  int tmp = M / L;
  int answer;
  for(int i = 1; i * i <= tmp; i++){
    if(tmp % i == 0 && checker(i, tmp/i) == 1){
      answer = i;
    }
  }
  cout<< answer * L << " " << tmp*L/answer<<endl;
}

3.2. 박인서

#include <iostream>

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

int main() {
	int a, b;
	std::cin >> a >> b;

	int c = b / a, r = 1;
	for (int i = 1; i*i <= c; i++)
		if (i*(c / i) == c && gcd(i,c/i)==1) r = i;

	std::cout << a*r << ' ' << a*c / r;
	return 0;
}

3.3. 곽정흠


4. 아이디어

4.1. 15이원준

  • 아 서로소 체크 저것도 있었군

4.2. 박인서

  • 최대공약수를 a, 최소공배수를 b라 하면 b=a*x*y가 되도록 하면 두 수 a*x와 a*y가 원래의 두 수가 된다.
  • 이때 x와 y는 자연수여야 되고, 서로소여야한다.
  • 위의 아이디어를 이용하여 문제를 풀었다.

4.3. 곽정흠

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:07
Processing time 0.0178 sec