BOJ/🥇

★Math & Geometry Advanced I - 2 Solved★

metamong 2024. 4. 27.

★ 1011 Fly me to the Alpha Centauri ★

★Math & Geometry Advanced I -  2 Solved★ - undefined - undefined - ★ 1011 Fly me to the Alpha Centauri ★
★Math & Geometry Advanced I -  2 Solved★ - undefined - undefined - ★ 1011 Fly me to the Alpha Centauri ★

import sys
input=sys.stdin.readline

for _ in range(int(input())):
    x,y=map(int,input().split())
    diff=y-x
    closest_root=int(diff**(1/2))
    if diff == (closest_root**2):
        print(closest_root*2-1)
    elif (diff-(closest_root**2))<=closest_root:
        print(closest_root*2)
    else:
        print(closest_root*2+1)

 

🍋 kn은 kn-1 / kn / kn+1 중 한 개만 가능 + 맨 앞과 맨 뒤의 거리 step은 1만 가능하다는 조건 하에 수학 규칙성을 찾는 문제

→ y-x를 diff라고 한다면, 중복된 step 간격 없이 오름차순 - 내림차순 형태의 수열을 형성할 수 있는 diff는 제곱수만 가능하다.

★Math & Geometry Advanced I -  2 Solved★ - undefined - undefined - ★ 1011 Fly me to the Alpha Centauri ★

🍋 위 그림과 같이 (입력 받은 두 x와 y의 diff를 n이라 가정)

① n이 제곱수라면 1 + 2 + ... + (√n-1) + n + ( n-1) + ... + 2 + 1은 ( n)^2이다. 이 때의 step은 2*( n) - 1.

 

floor(√n)과 floor( √(n))+1 사이의 숫자

→ floor( √n)+1 ≤ n ≤ floor( n)+ √n이라면 step은 2*( floor( n))

→ floor( √n) + √n < n < floor( √(n))+1이라면 step은 2*(floor( √n))+1

 

🍋 floor(√n)만큼 오른쪽 감소부분 숫자가 1씩 감소하는 부분 수열이 될 때까지 1씩 부분부분 숫자가 증가하고, floor( √n)만큼 왼쪽 증가부분 숫자가 1씩 증가하는 부분 수열이 될 때까지 1씩 부분부분 숫자가 증가한다.


★ 1484 다이어트 ★

★Math & Geometry Advanced I -  2 Solved★ - undefined - undefined - ★ 1484 다이어트 ★
★Math & Geometry Advanced I -  2 Solved★ - undefined - undefined - ★ 1484 다이어트 ★

G=int(input())
ans=[]
for a in range(1,int(G**(1/2))+1):
    if G%a==0:
        b=G//a
        if (a+b)%2==0 and a!=b:
            ans.append((a+b)//2)
if not ans: print(-1)
else: print(*sorted(ans),sep='\n')

 

🍋 주어진 G에서 G = x^2 - y^2을 만족하는 x를 찾는 문제. G = x^2-y^2 = (x-y)(x+y)로 나타낼 수 있고, 예측한 몸무게 y는 0이 아닌 자연수인 조건과, G의 약수를 돌려(root(G)까지 돌림) (x-y)와 (x+y)를 합한 결과가 2로 나누어지는 경우만 x를 구할 수 있으므로 그 때의 x를 출력