Hdu 2035 people see people love a^b

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=2035

People See people love a^bdescription

An integer representing the last three digits of the a^b.
Description: The meaning of A^b is "A's B-square"

Input

The input data contains multiple test instances, one row per instance, consisting of two positive integers a and B (1<=a,b<=10000), and if a=0, b=0, indicates the end of the input data and does not process.

Output

For each test instance, output an integer representing the last three bits of a^b, one row for each output.

Sample Input

2 3
12 6
6789 10000
0 0

Sample Output

8
984
1

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < cstdio> #include <vector> #include <map>using std::map;using std::min;using std::find;using std::p air; Using std::vector;using std::multimap; #define PB (E) push_back (e) #define SZ (c) (int) (c). Size () #define MP (A, b) make_pair (A, B) #define ALL (c) (c). Begin (), (c). End () #define ITER (c) __typeof ((c). Begin ()) #define CLS (arr, Val) memset (arr, Val, si Zeof (arr)) #define Cpresent (C, E) (Find (All (c), (e))! = (c). End ()) #define REP (i, n) for (int i = 0; i < (int) n; i++) #defi NE tr (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) const int M = 1000;const int N = 100001;const int INF = 0x3f3    F3f3f;void pow_mod (int A, int B) {int ans = 1;        while (b) {if (b & 1) ans = ans * A% M;        A = A * a% M;    B >>= 1; } printf ("%d\n", ans);}    int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin);    Freopen ("OUT.txt", "w+", stdout); #endif int A, B;while (~SCANF ("%d%d", &a, &b), A + b) {Pow_mod (A, b); } return 0;}

Hdu 2035 people to see people love a^b

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.