• 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 }
  • 相关阅读:
    Sqlite EF6注册
    C# 等值锁定
    net 4.0+EF6+Sqlite 使用,安装,打包
    C#调用C++函数
    C# 调用.exe文件
    Java继承
    python多线程与threading模块
    Java对象构造
    python多线程与_thread模块
    Linux文件压缩与打包
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5689862.html
Copyright © 2020-2023  润新知