import sys
import math

if sys.version_info < (3,):
    range = xrange

def primes(upto, func):
    if upto > 25000: return large_primes(upto, func)
    upto -= 1
    flags = [True] * upto
    for i in range(upto-1):
        if flags[i]:
            prime = i + 2
            k = i + prime
            while k < upto:
                flags[k] = False
                k += prime
            func(prime)

def large_primes(upto, func):
    # The Algorithm is adapted from http://w...content-available-to-author-only...k.com/~jrm/printprimes.html
    # This code is a translated version of Andreas Raab's #largePrimesUpTo:do: method
    # which was written for the Squeak Smalltalk environment.

    idx_limit = math.sqrt(upto) + 1
    flags = [0xFF] * (int((upto + 2309) / 2310) * 60 + 60)
    primes_up_to_2310 = []
    primes(2310, lambda p: primes_up_to_2310.append(p))
    mask_bit_idx = [None]*2310
    mask_bit_idx[0] = 0
    mask_bit_idx[1] = 1
    bit_idx = 1
    for i in range(5):
        func(primes_up_to_2310[i])
    idx = 5
    for n in range(2, 2310):
        while primes_up_to_2310[idx] < n: idx += 1
        if n == primes_up_to_2310[idx]:
            bit_idx += 1
            mask_bit_idx[n] = bit_idx
        elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0 or n % 7 == 0 or n % 11 == 0:
            mask_bit_idx[n] = 0
        else:
            bit_idx += 1
            mask_bit_idx[n] = bit_idx
    for n in range(13, upto, 2):
        mask_bit = mask_bit_idx[n % 2310]
        if mask_bit:
            byte_idx = int(n / 2310) * 60 + (mask_bit-1 >> 3)
            bit_idx = 1 << (mask_bit & 7)
            if flags[byte_idx] & bit_idx:
                func(n)
                if n < idx_limit:
                    idx = n * n
                    if (idx & 1) == 0: idx += n
                    while idx <= upto:
                        mask_bit = mask_bit_idx[idx % 2310]
                        if mask_bit:
                            byte_idx = int(idx / 2310) * 60 + (mask_bit-1 >> 3)
                            mask_bit = 255 - (1 << (mask_bit & 7))
                            flags[byte_idx] = flags[byte_idx] & mask_bit
                        idx += 2 * n

max = int(sys.argv[1]) if len(sys.argv) == 2 else 100
q = c = 0

def f(p):
    global q, c
    q = p
    c += 1

primes(max, f)
print(q, c)
