Fermat vs. Pythagoras
Time Limit: 2000MS |
|
Memory Limit: 10000K |
Total Submissions: 1493 |
|
Accepted: 865 |
Description
Computer generated and assisted proofs and verification occupy a small niche in the realms of computer science. The first proof of the four-color problem is completed with the assistance of a computer program and current efforts in V Erification has succeeded in verifying the translation of high-level code down to the chip level.
This problem deals with computing quantities relating to part of Fermat's last theorem:that there is no integer solution S of a^n + b^n = c^n for n > 2.
Given a positive integer N, you is to write a program that computes the quantities regarding the solution of x^2 + y^2 = Z^2, where x, Y, and Z areconstrained(driven)To is positive integers less than or equal to N. You is to compute the number of triples (x, y, z) such that x < Y < Z, and they is relatively prime, i.e., with no C OmmonDivisor(divisor)Larger than 1. You were also to compute the number of values 0 < p <= N such that P was not part of any triple (not just relatively p Rime triples).
Input
The input consists of a sequence of positive integers, one per line. Each integer in the input file would be less than or equal to 1,000,000. Input is terminated by end-of-file
Output
For each of the integer N in the input file print, the integers separated by a space. The first integer is the number of relatively prime triples (such, component of the triple is <=n). The second number is the number of positive integers <=n this is not a part of any triple whose, all <= N. There should is one output line for each input line.
Sample Input
1025100
Sample Output
1 44 916 27
Test instructions: Given an n, the output ternary group (A,B,C) where A,b,c 22 coprime, and a²+b²=c², and 1~n does not appear in any of the number of triples.
This problem needs to know the nature of the tick.
First, for a set of tick, ①a and B's parity, ②c must be an odd number.
Proof ①: If A and b are the same even, then C is even, with a,b,c 22 coprime contradiction; If A and B are odd, c must be even, set a=2*i+1,b=2*j+1,c=2*k-a²+b²=c²->2*i²+2*i+2*j²+2*j+1=2 *k², this equation is contradictory.
Prove that ②:a,b a odd and even, apparently.
Then will a²+b²=c² deformation, a²= (c+b) * (c-b), easy to find c-b and c+b coprime, so c-b and c+b are square number, set X²=c-b,y²=c+b, a=x*y,b= (y²-x²)/2,c= (y²+x²)/2.
Easy to get x, Y are odd, directly enumerate X, Y and so on.
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <cmath>5 using namespacestd;6 Const intmaxn=1000010;7 BOOLVIS[MAXN];8 Long LongGCD (Long LongALong Longb) {9 returnB? GCD (b,a%b): A;Ten } One intMain () { A intN,m,ans,tot; - while(~SCANF ("%d",&N)) { -M= (int) sqrt (n+0.5); ans=tot=0; thememset (Vis,0,sizeof(Vis)); - for(intt=1; t<=m;t+=2) - for(ints=t+2;(s*s+t*t)/2<=n;s+=2) - if(GCD (s,t) = =1){ + inta=s*T; - intb= (s*s-t*t)/2; + intC= (s*s+t*t)/2 Aans++; at for(intk=1; k*c<=n;k++){ -vis[k*a]=true; -vis[k*b]=true; -vis[k*c]=true; - } - } in for(intI=1; i<=n;i++) - if(!Vis[i]) totot++; +printf"%d%d\n", Ans,tot); - } the}
Number theory (Pythagorean theorem): POJ 1305 Fermat vs. Pythagoras