-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17626.cpp
More file actions
43 lines (39 loc) · 876 Bytes
/
17626.cpp
File metadata and controls
43 lines (39 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int n,res=5;
cin>>n;
for(int i=sqrt(n);i>=1&&res>1;i--){
int a=i*i;
if(n==a) {
res=1;
break;
}
for(int j=sqrt(n-a);j>=1&&res>2;j--){
int b=j*j;
if(n==a+b) {
res=2;
}
for(int k=sqrt(n-a-b);k>=1&&res>3;k--){
int c=k*k;
if(n==a+b+c) {
res=3;
}
for(int l=sqrt(n-a-b-c);l>=1&&res>4;l--){
int d=l*l;
if(n==a+b+c+d) {
res=4;
}
}
}
}
}
cout<<res;
return 0;
}