You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
수식을 조금 이용하면 된다.
먼저 구하고자 하는 favorite number를 m으로 두면
x = N / m = N % m
이 성립해야 되고, 양쪽으로 식을 정리하면
N = m * x + x
m = (N - x) / x
이 된다.
단, 1부터 모든 n까지 탐색은 시간 초과가 되므로 sqrt(n) 까지만 돌려주면 된다.
Source Code
#include<iostream>usingnamespacestd;intmain() {
longlong n;
cin >> n;
longlong ans = 0;
for (longlong x = 1; x * x <= n; x++)
{
longlong m = (n - x) / x;
if (m == 0)
{
continue;
}
if (n / m == n % m)
{
ans += m;
}
}
cout << ans << endl;
}
This discussion was converted from issue #17 on September 15, 2026 10:44.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d
Problem Summary
주어진 N에 대해 나눈 몫과 나머지가 같도록 하는 m을 모두 구해 더하면 된다.
Solution
수식을 조금 이용하면 된다.
먼저 구하고자 하는 favorite number를 m으로 두면
이 성립해야 되고, 양쪽으로 식을 정리하면
이 된다.
단, 1부터 모든 n까지 탐색은 시간 초과가 되므로 sqrt(n) 까지만 돌려주면 된다.
Source Code
All reactions