zoukankan      html  css  js  c++  java
  • 杭电1097-A hard puzzle

    Problem Description
    lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
    this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
     
    Input
    There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
     
    Output
    For each test case, you should output the a^b's last digit number.
     
    Sample Input
    7 66
    8 800
     
    Sample Output
    9
    6
     
     

    题目分析:

    1^1=1 1^2=1 1^3=1 1^4=1 1^5=1 ...从4次方开始周期为1
    2^1=2 2^2=4 2^3=8 2^4=6 2^5=2 ...从4次方开始周期为4
    3^1=3 3^2=9 3^3=7 3^4=1 3^5=3 ...从4次方开始周期为4
    4^1=4 4^2=6 4^3=4 4^4=6 4^5=4 ...从4次方开始周期为2
    ...
    9^1=9 9^2=1 9^3=9 9^4=1 9^5=9 ...从4次方开始周期为2

    同时要理解题目下方 (a%10)和a相同的幂次方尾数的结果是相同的,

    #include<stdio.h>
    main()
    {
        int a,b,c;
        while(~scanf("%d%d",&a,&b))
        {
            b%=4;a%=10;c=a;
            if(b==0)
            b=4;
            while(--b)
            c=c*a%10;
            printf("%d ",c);
        }
    }
  • 相关阅读:
    算法-在字符串中删除特定的字符或字符串
    Linux 下的7种文件类型
    TCP/IP协议、三次握手、四次挥手
    8、VUE自定义组件
    7、VUE事件
    6、VUE指令
    Redis高级功能-1、高并发基本概述
    5、插值
    4、VUE生命周期
    3、Vue实例的属性
  • 原文地址:https://www.cnblogs.com/wft1990/p/4333993.html
Copyright © 2011-2022 走看看