#include #include #include #define sq 3 using namespace std; typedef unsigned char byte; template inline T gcd(T a, T b) { while(b) { auto t = a % b; a = b; b = t; } return a; } int main() { auto start = chrono::system_clock::now(); //triangles for which either (x1,y1) == (0,0) //or x1==0,y1!=0 or x1!=0,y1==0 long count = 3*sq*sq; for (int vx = 1; vx <= sq; vx++) for (int vy = 1; vy <= sq; vy++) { int dx = -vy/gcd(vx,vy); int dy = vx/gcd(vx,vy); for (int d = 1; vx+dx*d >= 0 && vy+dy*d <= sq; d++) count++; for (int d = -1; vx+dx*d <= sq && vy+dy*d >= 0; d--) count++; } auto end = std::chrono::system_clock::now(); std::chrono::duration elapsed_seconds = end-start; cout << "solving took: " << elapsed_seconds.count() << endl; cout << "triangles: " << count; return 0; }