-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem39.cpp
More file actions
48 lines (44 loc) · 1.3 KB
/
Problem39.cpp
File metadata and controls
48 lines (44 loc) · 1.3 KB
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
44
45
46
47
48
/*
Krishna Mohan
Project Euler - Problem 39
Date: 3/22/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 1001
bool isPerfectSquare(int n)
{
int sq=sqrt(n);
return (sq*sq)==n;
}
int main() {
int p[MAX];
int h, pm, sq;
memset(p, 0, sizeof(p));
for(int i=1;i<MAX;i++)
{
for(int j=1;j<MAX;j++)
{
h=pow(i, 2)+pow(j, 2);
pm=i+j+sqrt(h);
if(isPerfectSquare(h) && pm<MAX)
{
//cout<<i<<" : "<<j<<" : "<<sqrt(h)<<endl;
p[pm]++;
}
}
}
int maxVal=0, pos=0;
for(int i=0;i<MAX;i++)
{
if(p[i]>maxVal)
{
maxVal=p[i];
pos=i;
}
}
//cout<<"120: "<<p[120]<<endl;
cout<<"Ans: "<<pos<<endl;
return 0;
}