zoukankan      html  css  js  c++  java
  • HDU 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

    2 3 4
     

    Sample Output

    7 6

    Hint

     In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the
    second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.

    N的N次方,只需要求N的个位数的N的方的个位数,同时有一个规律,
    1 1 1 1 1 1 1 1
    2 4 8 6 2 4 8 6
    3 9 7 1 3 9 7 1
    4 6 4 6 4 6 4 6
    5 5 5 5 5 5 5 5
    6 6 6 6 6 6 6 6
    7 9 3 1 7 9 3 1
    8 4 2 6 8 4 2 6
    1 9 1 9 1 9 1 9
    所以应该很简单把
     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 int main()
     5 {
     6     int t;
     7     int n;
     8     int i,j;
     9     while(cin>>t)
    10     {
    11         while(t--)
    12         {
    13             cin>>n;
    14             i=n%10;
    15             j=n%4;
    16             if(j==0)
    17                 cout<<i*i*i*i%10<<endl;
    18             else
    19             {
    20                 int ans=1;
    21                 while(j--)
    22                 {
    23                     ans*=i;
    24                     ans=ans%10;
    25                 }
    26                 cout<<ans<<endl;
    27             }
    28         }
    29     }
    30     return 0;
    31 }
  • 相关阅读:
    Js/Jquery获取iframe中的元素
    js常用技巧汇总
    jquery常用技巧
    Tomcat远程调试
    常用SQL
    CRM-stark组件
    面试题-linux基础
    vue2-通过axios实现数据请求
    Vue01
    面试题之python基础
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5689862.html
Copyright © 2011-2022 走看看