Title: Find the naïve solution of a tick array of less than N (three number coprime) and find the number of digits not appearing in all the tick arrays in [1, N].
Analysis: Number theory. In this case, the solution can be directly used in "original".
x = 2st,y = S^2-t^2,z = s^2 + t^2,
Where: 1.s > t; (enumeration order)
2.s and T coprime; (naive solution)
3.s and t parity are different; (contradiction proof)
When calculating numbers that do not appear, you need to enumerate the multiples of the naïve solution.
Description: The great Euclid was ╮(╯▽╰)╭.
#include <cstring> #include <cstdio> #include <cmath>//x = 2st, y = s^2-t^2, z = s^2+t^2int gcd (int A, in T b) {return a%b?gcd (b, a%b): b;} int Visit[1000001];int Main () {int N, x, Y, Z;while (~scanf ("%d", &n)) {memset (visit, 0, sizeof (visit)); int maxt = (int) sqrt (n+0.0), count = 0;for (int t = 1; t <= maxt; + + t) {int maxs = (int) sqrt (0.0 + n-t*t); if (Maxs > maxt) maxs = maxt;for (int s = t+1; s <= maxs; + + s) if (s%2! = t%2 && gcd (S, t) = = 1) {Count ++;x = 2*s*t;y = S*s-t*t;z = S*s + t*t;//solves the non-naïve solution for (int k = 0; k*z <= N; + + k) Visit[x*k] = Visit[y*k] = Visit[z*k] = 1;}} int p = 0;for (int i = 1; I <= N; + + i) p + = (visit[i]==0);p rintf ("%d%d\n", count, p);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVa 106-fermat vs. Pythagoras