Manasa and Calculations

Sort by

recency

|

6 Discussions

|

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from functools import reduce
    m = 1000000007
    
    def mul_m(a, b):
        return a * b % m
    
    def zpow(a, b, m):
        return 0 if b == 0 else pow(a, b, m)
    
    n = int(input())
    a = [0] * n
    b = [0] * n
    p = [0] * n
    for i in range(n):
        p[i], b[i], a[i] = map(int, input().split())
    B = reduce(mul_m, [pow(p[i], b[i], m) for i in range(n)])
    if all(a[i] == b[i] for i in range(n)):
        print(B * 2 % m)
    else:
        print(B * reduce(mul_m, [1 + zpow(p[i], a[i] - b[i], m) for i in range(n)]) % m)
    
  • + 0 comments

    You forgot to mention m >= 0, otherwise the result is different.

  • + 0 comments

    Can anyone please tell me how to improve my code efficiency? I wrote this but its showing runtime error for most testcases. It is in python 3.

    from fractions import gcd
    n = int(input())
    A = 1
    B = 1
    for _ in range(n):
        p1,b1,a1 = map(int, input().split())
        A *= pow(p1,a1)
        B *= pow(p1,b1)
    num = 0
    for j in range(B,A+1,B):
        for k in range(B,A+1,B):
            if j <= k and gcd(j,k) == B and j*k == A*B:
                num += j+k
    print(num%(pow(10,9)+7))
    
  • + 0 comments

    hav u checked for modular overflows and when m=n

  • + 0 comments

    Hi! Could someone please take a look at my submitted code? It is working for all test cases except 12 and 13(wrong answer). I have checked for boundary conditions as well. Any help is appreciated!