[BOJ] 3933 라그랑주의 네 제곱수 정리

Time Lapse :NONE

3933.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#define gc() getchar_unlocked()
#define FFF(a,b) ((a<<3)+(a<<1)+(b&0b1111));
int ans[32769] = {0, };
void f(int c, int d, int s){
if (c > 32769||!d) return;
ans[c]++;
for (register int i = s; i*i <= 32769 - c; i++) f(c + i * i, d - 1, i);
}
int fRI() {
int ret = 0, N = gc();
for (; 0x30>N || N>0x3A; N = gc());
for (; 0x30 <= N && N <= 0x3A; N = gc()) ret = FFF(ret, N)
return ret;
}
int main(void){
register int cache;
f(0, 5, 1);
while (cache=fRI()) printf("%d\n", ans[cache]);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/3933/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.