isFriendCheating?

samuel Jo·2022년 12월 20일
0

codewars

목록 보기
15/46

문제 설명.

A friend of mine takes the sequence of all numbers from 1 to n (where n > 0).

Within that sequence, he chooses two numbers, a and b.

He says that the product of a and b should be equal to the sum of all numbers in the sequence, excluding a and b.

Given a number n, could you tell me the numbers he excluded from the sequence?

예시
Examples:
removNb(26) should return [(15, 21), (21, 15)]
or
removNb(26) should return { {15, 21}, {21, 15} }
or
removeNb(26) should return [[15, 21], [21, 15]]
or
removNb(26) should return [ {15, 21}, {21, 15} ]
or
removNb(26) should return "15 21, 21 15"

일단 1~n까지의 합을 구하는 공식은 n(n+1)/2 이다.
이걸 sum 으로 두고
sum = n(n+1)/2
이 합이 a,b를 곱한값과 같은데 sum -a-b를 해줘야한다.

b를 기준으로 잡을지 a를기준으로 잡을지는 전혀 중요하지 않다. 나 같은 경우 b를 기준으로 잡았구, if문을 통해 빈배열에 push해주게끔 했다. a< n이고 정수인경우만.

정말 오랜만에 푼다.

profile
step by step

0개의 댓글