import random
import math
random.seed("spb-team-2014")

class TestGen:
    def __init__(self):
        self.test_number = 0

    def generate_samples(self):             
        self.print_test(3, 4)
        self.print_test(1, 12)                                                      

    def generate_min_tests(self):
        self.print_test(1, 1)
        self.print_test(1, 2)
        self.print_test(2, 2)
        self.print_test(2, 1)
        self.print_test(1, 6)
        self.print_test(1, 9)
        self.print_test(6, 1)
                                                            
    def generate_hand_tests(self):
        self.print_test(1, 1000000000)
        self.print_test(4, 48)
        self.print_test(2, 9)
        self.print_test(9, 2)
        self.print_test(239017 * 239 * 13, 239017 * 17 * 241)
        self.print_test(239017 * 239 * 13, 239 * 239013 * 11)

    def generate_primes(self, maxn):
        is_prime = [True for i in range(maxn)]
        primes = []
        for i in range(2, maxn):
            if not is_prime[i]:
                continue
            primes.append(i)
            for j in range(i + i, maxn, i):
                is_prime[j] = False
        return primes
        
    def generate_random_number(self, maxn, primes):
        #need better number?
        return random.randint(1, maxn)    
                                       
    def generate_random_test(self, maxn, primes):
        a = self.generate_random_number(maxn, primes)
        b = self.generate_random_number(maxn, primes)
        self.print_test(a, b)
     
    def generate_max_tests(self, maxn):
        self.print_test(10**9 - 1, 10**9)
        self.print_test(10**9 - 239, 10**9)
        self.print_test(1, 10**9)
        self.print_test(10**9 // 2, 10**9)
        self.print_test(10**9 // 5, 10**9)
        self.print_test(2 * 5 * 23 * 41 * 43 * 47 * 51, 7 * 13 * 17 * 19 * 29 * 31 * 37)
        self.print_test(5 * 7 * 19 * 23 * 31 * 41 * 51, 2 * 13 * 17 * 29 * 37 * 43 * 47)
        self.print_test(999999937, 999999929)
        self.print_test(999999751, 999999757)
        self.print_test(999999739, 999999599)
        self.print_test(999997357, 999997403)
        self.print_test(999999937, 2)
        self.print_test(999999937, 5)
        self.print_test(499999993 * 2, 2)
        self.print_test(499999993 * 2, 3)
        self.print_test(90909089 * 11, 2)
        self.print_test(90909089 * 9, 3)
        self.print_test(90909089 * 7, 5)
        self.print_test(90909089 * 10, 12)
        self.print_test(90909089 * 11, 499999993 * 2) 
        self.print_test(90909089 * 11, 999999937)
        self.print_test(499999993 * 2, 999999929)
        self.print_test(499999993 * 2, 999999757) 
        self.print_test(333333313 * 3, 999999929)
        self.print_test(90909089 * 7, 999999929)
                                    
    def print_test(self, x, y):
        self.test_number += 1
        test_name = "../tests/" + "{0:0=2d}".format(self.test_number)
        test_file = open(test_name, "w")
        print(x, y, file=test_file)
        test_file.close()

    def generate_all_tests(self):
        maxn = 10**9

        self.generate_samples()                               #2 tests
        self.generate_min_tests()                             #7 tests
        self.generate_hand_tests()                            #6 tests
        
        primes = self.generate_primes(int(math.sqrt(maxn)))
        for i in range(20):                                   #20 tests
            self.generate_random_test(maxn, primes)
        self.generate_max_tests(maxn)                         #17 tests

import os, shutil
if os.path.exists('../tests'):
    shutil.rmtree('../tests', ignore_errors=False, onerror=None)
try:
    os.makedirs('../tests')
except OSError:
    pass

import time
start = time.time()
writer = TestGen()
writer.generate_all_tests()
finish = time.time()
print('All tests were generated. Elapsed time: ', finish - start)