hdu1097

这篇博客探讨了一个简化版的数学难题,即如何仅通过个位数确定两个数相乘结果的个位数。作者提供了一段Java代码来解决这个问题,重点在于找出幂运算的个位数规律,特别是当指数具有特定模4的余数时。博客鼓励读者思考并简化问题,而不是回避挑战。
摘要由CSDN通过智能技术生成

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.

import java.util.Scanner;
public class test2 {
    public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      while (sc.hasNext()){
          double a=sc.nextInt();
          int b=sc.nextInt();
          double d=a%10;
          double []c=new double[4];
          for (int i = 0; i < c.length; i++) {
              c[i]=Math.pow(d,i+1);
          }
          if(b==0){
              System.out.println(1);
          } else if (b%4==0) {
              System.out.println((int)(c[3]%10));
          } else {
              System.out.println((int)(c[b%4-1]%10));
          }
      }
    }
}z怎么说呢千万不要落下这个幂的隐藏规律,就是只要管个位数字即可。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值