-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path504.cpp
More file actions
39 lines (37 loc) · 1.16 KB
/
Copy path504.cpp
File metadata and controls
39 lines (37 loc) · 1.16 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
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
bool isPerfectSquare(int num) {
double sq = sqrt(num);
return sq == (int)sq;
}
int main() {
int m = 100;
long long ans = 0;
for (int a = 1; a <= m; a++) {
for (int b = 1; b <= m; b++) {
for (int c = 1; c <= m; c++) {
for (int d = 1; d <= m; d++) {
int noOfLatticePoints = a + b + c + d - 3;
for (int i = 1; i <= a; i++) {
double x = b - (b*1.0/a)*i;
double y = d - (d*1.0/a)*i;
if(x > 0) noOfLatticePoints += (x == (int)x) ? x - 1 : floor(x);
if(y > 0) noOfLatticePoints += (y == (int)y) ? y - 1 : floor(y);
}
for (int i = 1; i <= c; i++) {
double x = b - (b*1.0/c)*i;
double y = d - (d*1.0/c)*i;
if(x > 0) noOfLatticePoints += (x == (int)x) ? x - 1 : floor(x);
if(y > 0) noOfLatticePoints += (y == (int)y) ? y - 1 : floor(y);
}
if(a%10 == 1) cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<noOfLatticePoints<<endl;
if(isPerfectSquare(noOfLatticePoints)) ans++;
}
}
}
}
cout<<ans<<endl;
return 0;
}