NOIP Simulation---1. Angry ljj (Anger)

Source: Internet
Author: User
Tags gcd

LJJ just finished a class! This class is a math class! He knows that. The addition and subtraction is a first-class operation, multiplication belongs to a two-level operation, the power is a three-level operation, and the priority of power > Multiplication Priority > The priority of the addition and subtraction (this is the math class in several grades). However, from the previous set of papers + Previous question, we know that LJJ is a person who is always a whim and not enough IQ (that is, he came up with a question for you). He invented a four-level operation, and we're going to use the sign # to indicate (no other symbol is found). We know A*b=a+a+a+...+a (plus b), a^b=a*a*a*a*...*a (multiply B), then a#b=a^a^a^a^...^a (Power operation B), natural, #的优先级比幂的优先级高. So, LJJ asked you to help him find a#b mod 1000000007. (PS: This is the most simple question of this paper)

Title Description

See topic Background

Input/output format

Input format:

Enter only 1 lines, that is, a, B.

Output format:

Output is only 1 lines, i.e. a#b mod 1000000007.

Input and Output Sample input example # #:
3 5
Sample # # of output:
968803245
Description

First of all, the sample answer is not mod is actually 4.4342648824303776994824963061915e+38 (from the person who malicious)

Then, the data range:

For 20% of data, a<=1000,b<=1000

For 50% of data, a<=10^16,b<=10000

For 100% of data, a<=10^16,b<=10^16

Analysis: http://blog.163.com/eden_284914869/blog/static/2522460782016799444725/

Good number theory nature (to be proved): a^ (b mod (prime-1)) mod prime = a^ B mod Prime (Prime is a prime number)

A^a^a......^a (b-time a) mod prime = a^ (a^ (b-1)) mod prime=a^ (a^ (b-1) mod (prime-1)) mod prime

Code:

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<bitset>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineVI vector<int>#definePII pair<int,int>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e5+Ten;Const intdis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q,ll mo) {ll F=1; while(q) {if(q&1) f=f*p%mo;p=p*p%mo;q>>=1;}returnF;}intN,m,k,t;ll A, b;intMain () {inti,j; scanf ("%lld%lld",&a,&b); printf ("%lld\n", Qpow (A%mod,qpow (a% (mod-1), B-1, mod-1) , MoD); //System ("pause");    return 0;}

NOIP Simulation---1. Angry ljj (Anger)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.