zoukankan      html  css  js  c++  java
  • hdu 1061 Rightmost Digit

    题目连接

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

    Rightmost Digit

    Description

    Given a positive integer N, you should output the most right digit of N^N.

    Input

    The 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).

    Output

    For each test case, you should output the rightmost digit of N^N.

    Sample Input

    3
    3
    5

    Sample Output

    7
    5

    快速幂。。

    #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::pair;
    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, sizeof(arr))
    #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    #define rep(i, n) for(int i = 0; i < (int)n; i++)
    #define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
    const int N = 100001;
    const int INF = 0x3f3f3f3f;
    typedef unsigned long long ull;
    ull pow_mod(int n) {
        ull ans = 1, x = n;
        while(n) {
            if(n & 1) ans = ans * x % 10;
            x = x * x % 10;
            n >>= 1;
        }
        return ans;
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w+", stdout);
    #endif
        int t, n;
        scanf("%d", &t);
        while(t--) {
            scanf("%d", &n);
            printf("%lld
    ", pow_mod(n));
        }
        return 0;
    }
  • 相关阅读:
    isequal 和startswith 使用
    UVa10340
    UVa1368
    UVa455
    UVa1225
    UVa1586
    UVa 1585
    UVa10082
    UVa272
    NYOJ1
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4792673.html
Copyright © 2011-2022 走看看