-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.cpp
More file actions
38 lines (36 loc) · 760 Bytes
/
13.cpp
File metadata and controls
38 lines (36 loc) · 760 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
#include <iostream>
using namespace std;
int main()
{
int r,b,k,min;
cout << "enter x" << endl;
cin >>r;
int *n=new int[r+1];
for (int i=0;i<r+1;i++){
n[i]=0;
}
int i=0;
k=0;
while (k<r+1){
k=i*i;
if (k<r+1)
n[k]=1;
i++;
}
for (int i=1;i<r+1;i++){
min=0;
for (int k=0;k<i/2+2;k++){
if ((n[k]!=0) && (n[i-k]!=0)){
if (min==0){
min=n[i-k]+n[k];
}
if (min>n[i-k]+n[k]){
min=n[i-k]+n[k];
}
}
}
if (n[i]!=1)
n[i]=min;
}
cout <<"n=" <<n[r]<< endl;
}