zoukankan      html  css  js  c++  java
  • 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次方的最后一位数字
     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     long long int n,i,j,ans,t,sum;;
     6     scanf("%lld",&t);
     7     while(t--)
     8     {
     9         scanf("%lld",&n);
    10         sum=1;
    11         ans=1;
    12         n=n%20;//找出规律,20个数一次循环
    13         if(n==0)
    14         {
    15             n=20;
    16         }//将范围缩小到20以内
    17         for(i=0;i<n;i++)
    18         {
    19             sum=ans*n;
    20             ans=sum%10;//(只要最后的一位)
    21         }
    22         ans=ans%10;
    23         printf("%lld
    ",ans);
    24     }
    25     return 0;
    26 }
  • 相关阅读:
    Mybatis连接配置文件详解
    MyBatis映射配置文件详解
    AGC 016 C
    CodeForces
    UVA
    某5道CF水题
    DZY Loves Chinese / DZY Loves Chinese II
    [SHOI2016] 黑暗前的幻想乡
    CodeForces
    CodeForces
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/9208592.html
Copyright © 2011-2022 走看看