hduj 1097 A hard puzzle

A hard puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 28814    Accepted Submission(s): 10315

Problem Description

lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.

this puzzle describes that: gave a and b,how to know the a^b‘s the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.

Input

There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)

Output

For each test case, you should output the a^b‘s last digit number.

Sample Input

7 66
8 800

Sample Output

9
6
#include<iostream>
#include<cstring>
using namespace std;

int q_mod(int a,int b,int c)
{
	int s=1;
	while(b)
	{
		if(b&1)   s=(s%10)*(a%c)%c;
		b=b>>1;
		a=(a%c)*(a%c)%c;
	}

	return s;
}

int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		cout<<q_mod(n,m,10)<<endl;
	}

	return 0;
}
时间: 2024-10-12 16:49:23

hduj 1097 A hard puzzle的相关文章

[2016-02-05][HDU][1097][A hard puzzle]

[2016-02-05][HDU][1097][A hard puzzle] HDU - 1097 A hard puzzle Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know

HDOJ 1097 A hard puzzle

Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.this puzzle describes that: gave a and b,how to know

hdoj 1097 A hard puzzle 【找规律】

题目大意:求a^b的最右边的数. 这道题是有规律的 解题报告: http://blog.csdn.net/shengweisong/article/details/38024619  但是注意数据很大,要用64位的整型,被坑了一次.. 题目链接:点击打开链接 代码: #include<stdio.h> int main() { __int64 n, m, i; while(scanf("%I64d%I64d", &n, &m) == 2){ __int64

HDUJ 1098 Ignatius&#39;s puzzle

Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6222    Accepted Submission(s): 4283 Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no

hdoj 1097 A hard puzzle (找规律)

A hard puzzle                            T   ime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29231    Accepted Submission(s): 10494 Problem Description lcy gives a hard puzzle to feng5166,lwg,JG

hdu 1097 A hard puzzle

Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.this puzzle describes that: gave a and b,how to know

HDU 1097.A hard puzzle【快速幂或规律】【8月12】

A hard puzzle Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin. this puzzle describes that: gave a and

HDU - 1097 - A hard puzzle (快速幂取模)

A hard puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 32633    Accepted Submission(s): 11672 Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a a

杭电 HDU 1097 A hard puzzle

A hard puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 32851    Accepted Submission(s): 11754 Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius:  gave a