HDU 1061 Rightmost Digit

来源:互联网 发布:优酷网络大电影分成 编辑:程序博客网 时间:2024/06/05 07:40

题目大意:

        现有t个测例,每个测例中都给出一个正整数N(1 ≤ N ≤ 1,000,000,000),对于每个测例要你输出N ^ N的个位数。

题目链接

代码:

/*                                                * Problem ID : HDU 1061 Rightmost Digit  * Author     : Lirx.t.Una                                                * Language   : C                               * Run Time   : 0 ms                                                * Run Memory : 200 KB                                               */ #include <stdio.h>intfstp( int a, int n ) {intans;ans = 1;while (n) {if ( n & 1 ) ans = ( ans * a ) % 10;a   = ( a * a ) % 10;n >>= 1;}return ans;}intmain() {intt;intn;scanf("%d", &t);while ( t-- ) {scanf("%d", &n);if ( !( n % 10 ) ) puts("0");else printf("%d\n", fstp( n % 10, n ));}return 0;}

0 0
原创粉丝点击