PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000061. Bộ ba Pythagoras (Fermat vs. Pythagoras)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bộ ba Pythagoras (Fermat vs. Pythagoras)
Fermat vs. Pythagoras
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given N, consider all positive integer triples x<y<z<=N satisfying x^2+y^2=z^2. A triple is primitive if gcd(x,y,z)=1. Compute the number of primitive triples and the number of positive integers at most N that belong to no Pythagorean triple whose three values are at most N (including nonprimitive triples).
Input
An integer N.
Output
Two integers: the primitive-triple count and the number of unused positive integers.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
10
Output
1 4
Explanation
The only primitive triple with hypotenuse at most 10 is (3,4,5). Its multiple (6,8,10) also exists, leaving 1,2,7,9 unused.