InGenious Genie 2


Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 250M

Authors:
Problem type

Yet again, they come across the same genie who now holds a number lock of 4 digits and won't let them pass him unless they give him the correct pattern of the lock. The four digits of the lock are p, q, r, s; which are the unit digits of the answers to 4 questions which he is going to ask.

Question for P = (the no of primes less than or equal to a given integer, n) - 1.

Question for Q= (the sum of primes less than or equal to n) - 2.

Question for R = (the sum of odd primes less than or equal to n) - 1.

Question for S = (the sum of even primes less than or equal to n) - 2.

Help them give the genie the correct numbers for them to go to the next level.

Input format:

The first line of input contains t, the number of test cases. Each line of a test case contains a single integer n.

Output format:

Print t lines, the answers to the t testcases.

Each line should contain 4 integers p, q, r, s which are the unit digits of the answers to 4 questions which he is going to ask.

Constraints:

1 <= t <= 10

3 <= n <= \(10^4\)

For 30% of the testcases

3 <= n <= \(10^2\)

For the remaining testcases:

Original constraints.

Sample input:

2
7
20

Sample output:

3 5 4 0
7 5 4 0

Comments


  • 0
    nishi  commented on July 23, 2019, 10:37 p.m.

    t=int(input()) if t>=1 and t<=104: for i in range(0,t): n=int(input()) if n>=3 and n<=1018: prime=[] for j in range(2,n+1):

                #print("j=",j)
                list=[]
                flag=0
                for k in range(1,n+1):
                    #print("k   ",k)
                    if j%k==0:
                        list.append(k)
                        #print("list",list)
                        #print("k",k)
                for k in range(0,len(list)):
                    if list[k]==1 and list[k+1]==j:
                        flag=2;
                        break
                if flag==2:
                    prime.append(j)
    
            P=len(prime)-1;
            sum=0;
            for j in range(0,len(prime)):
                sum+=prime[j]
            Q=sum-2
            sum_O=0
            for j in range(0,len(prime)):
                if prime[j]%2!=0:
                    sum_O+=prime[j]
            R=sum_O-1
            S=0
            print(P,Q%10,R%10,S)

    """

    1. The output for Q and R is the value %10(According to sample output). 2.For input as : 5 50 40 65 85 55

    Output is 14 6 5 0

    11 5 4 0

    17 9 8 0

    22 2 1 0

    15 9 8 0

    But some of the outputs get printed twice.