Semi-prime H-numbers

Time limit1sMemory limit128 MB

Summary
For each H-number h, count H-semi-primes up to h, where H-primes are irreducible among numbers of the form 4n+1.
Level

Medium6 of 10

Topics
Number theory, Math, Prefix sum, Brute force
Solved
No attempts yet

Problem

This problem is based on an exercise proposed by David Hilbert, who suggested studying the theory of numbers of the form 4n+14n+1. Here we explore only a small part of it.

An H-number is a positive integer that is one more than a multiple of four: 1,5,9,13,17,21,…1, 5, 9, 13, 17, 21, \dots are the H-numbers. For this problem we pretend that these are the only numbers. The H-numbers are closed under multiplication.

Just as with the ordinary integers, we partition the H-numbers into units, H-primes, and H-composites. 11 is the only unit. An H-number hh is an H-prime if it is not the unit and can be written as a product of two H-numbers in exactly one way, namely 1×h1 \times h. All remaining H-numbers are H-composites.

For example, the first few H-composites are 5×5=255 \times 5 = 25, 5×9=455 \times 9 = 45, 5×13=655 \times 13 = 65, 9×9=819 \times 9 = 81, and 5×17=855 \times 17 = 85.

Your task is to count the H-semi-primes. An H-semi-prime is an H-number that is the product of exactly two H-primes; the two H-primes may be equal or different. In the example above, all five numbers are H-semi-primes. By contrast, 125=5×5×5125 = 5 \times 5 \times 5 is not an H-semi-prime, because it is the product of three H-primes.

Input

Each line contains an H-number hh with 1≤h≤10000011 \le h \le 1000001. The final line contains 00 and must not be processed.

Output

For each input H-number hh, print a single line containing hh and the number of H-semi-primes between 11 and hh inclusive, separated by a single space.

Examples1

  1. Example 1

    Input
    21
    85
    789
    0
    
    Expected output
    21 0
    85 5
    789 62