Sort by

recency

|

5 Discussions

|

  • + 1 comment

    Python3 solution

    lim = 3200
    mark = bytearray(lim)
    primes = [2]
    for i in range(3, lim, 2):
        if mark[i]: continue
        primes.append(i)
        for j in range(3 * i, lim, 2 * i):
            mark[j] = 1
    
    def factor(n):
        f = {}
        for p in primes:
            if p * p > n: break
            while n % p == 0:
                n //= p
                f[p] = f.get(p, 0) + 1
        if n > 1: f[n] = 1
        return f
    
    T = int(input())
    for t in range(T):
        n1, k1, n2, k2, n = map(int, input().split())
        if n1 == 0:
            f1 = 1 if k1 == 0 else 0
        else:
            f1 = pow(n1, k1, n) or n
        if n2 == 0:
            f2 = 1 if k2 == 0 else 0
        else:
            phi = 1
            for p, e in factor(n).items():
                phi *= (p - 1) * p ** (e - 1)
            f2 = pow(n2, k2, phi) or phi
        print(pow(f1, f2, n))
    
  • + 0 comments

    Your point about Devu Vs Police looked me little confusing but no worries I have shared your post with one of my old https://assignmentjunkie.co.uk/do-my-assignment collegue.I shall share the reviews little later.Thanks.

  • + 1 comment

    static BigInteger solve(int n1, int k1, int n2, int k2, int n) { String s1 = String.valueOf(n1); String s2 = String.valueOf(n2); String s3 = String.valueOf(n); BigInteger b1, b2, b3; b1 = new BigInteger(s1); b2 = new BigInteger(s2); b3 = new BigInteger(s3); b1 = b1.pow(k1); b2 = b2.pow(k2); int i = b2.intValue(); BigInteger result = b1.pow(i); result = result.mod(b3); return result; }

  • + 0 comments

    Hints:

    (1) Euler's theorem: if a and n are coprime positive integers, we have

    a^phi(n) mod n = 1,
    

    where phi() is Euler's totient function. Fermat's little theorem is a special case of this where n is prime.

    (2) What if a and n are not coprime? Try this:

    a mod n = (a/d mod n/d)*d,
    

    where d=gcd(a,n) is the greatest common divisor of a and n.

    These are the main ingredients of this problem. Watch out for boundary cases.

  • + 1 comment
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    long long n1,k1,n2,k2,n,t,i,f,j,l;
    cin>>t;
    for(i=0;i<t;i++)
    {cin>>n1>>k1>>n2>>k2>>n;
        if(n1==0 && k1==0)
            j=1;
        j=pow(n1,k1);
        if(n2==0 && k2==0)
            l=1;
        l=pow(n2,k2);
     if (j==0 && l==0)
         f=1;
    
        f=pow(j,l);
        cout<<f%n<<'\n';
    }
    giving error in some tests
    dont know what is wrong with this code?
    

No more comments