페이지

1977번: 완전제곱수

https://www.acmicpc.net/problem/1977


$O(\sqrt n)$

완전제곱수를 조사한다.


#include<cstdio>
int a, b, r, s;
int main() {
    scanf("%d %d", &a, &b);
    for (int i = 1; i*i <= b; i++) if (i*i >= a) {
        s += i*i;
        if (!r) r = s;
    }
    if (!s) puts("-1");
    else printf("%d\n%d", s, r);
    return 0;
}

댓글 없음 :

댓글 쓰기