首页 > 学院 > 开发设计 > 正文

HPUOJ---2017寒假作业--专题-1/N-Rightmost Digit

2019-11-08 00:50:24
字体:
来源:转载
供稿:网友

N - Rightmost Digit

 Given a positive integer N, you should output the most right digit of N^N. InputThe input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single positive integer N(1<=N<=1,000,000,000). OutputFor each test case, you should output the rightmost digit of N^N. Sample Input
234Sample Output
76
#include<stdio.h>int Quick_MI(int n,int m,int c){	int s=1;	n=n%c;	while(m)	{			if(m&1)		{			s=(s*n)%c;				}		n=(n*n)%c;		m=m/2;	}                     //快速幂 	return s;}int main(){	int T,N,k,c=10;	scanf("%d",&T);	while(T--)	{		scanf("%d",&N);		k=Quick_MI(N,N,c);		PRintf("%d/n",k);	}	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表