HDOJ 1061 Rightmost Digit(循环问题)
发布日期:2021-06-29 13:33:06
浏览次数:3
分类:技术文章
本文共 1509 字,大约阅读时间需要 5 分钟。
Problem 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 4Sample Output
7 6题意:很简单,就是输出n^n的最后一个数字时什么。
思路:前面有过一个0-9的n次方的题目,HDOJ1097题,那一题中我用代码推出了循环节,这个题目,我用的循环节全为4了.
HDOJ1097题博客链接:import java.util.Scanner;public class Main{ static long db[][] = new long[10][4]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); dabiao();// System.out.println(db[4][0]);// System.out.println(db[4][3]);// long t = sc.nextLong(); while(t-->0){ int n = sc.nextInt(); int f=n%10; int m=n%4; //System.out.println(m); m--; if(m<0){ m=3; } System.out.println(db[f][m]); } } private static void dabiao() { for(int i=1;i<=9;i++){ for(int j=0;j<4;j++){ db[i][j]=dabiao(i,j); //System.out.print(db[i][j]+" "); } //System.out.println(); } } private static long dabiao(long i, long j) { long m=i;//4,3 for(int k=1;k<=j;k++){ m=(m*i)%10; } m=m%10; return m; }}
转载地址:https://chenhx.blog.csdn.net/article/details/51029106 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月28日 06时20分41秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
面试笔试易错知识点Java篇八
2019-04-29
弹性事务框架ETF4J——面向Java微服务的交易最终一致性解决方案
2019-04-29
【Scala 教程】Scala 条件与循环语句
2019-04-29
【Scala 教程】Scala 集合类型
2019-04-29
JAVA 线程同步机制 synchronized
2019-04-29
MySQL 安装教程(无脑版)
2019-04-29
IDEA 怎么删除一个Module
2019-04-29
走进数据科学:最好是通过比网课更好的方法
2019-04-29
AI革命第一步:最容易被忽略但必不可少的物联网
2019-04-29
2020年开发运维工具清单:选择开发运维工具堆栈吧
2019-04-29
效率提升法则:高效人士不会去做的4件事
2019-04-29
8.PostgreSQL约束
2019-04-29
【技术分享】使用AES加密技术保障数据安全
2019-04-29
【应用实例】布线多?成本高?不可靠?泽耀方案没烦恼!
2019-04-29
数据可视化工具:Matplotlib绘图
2019-04-29
用Python写个超级小恐龙跑酷游戏,上班摸鱼我能玩一天
2019-04-29
闺蜜看我用Python画了一幅樱花图,吵着要我给他介绍程序员小哥哥
2019-04-29
【Python爬虫实战】知乎热榜数据采集,上班工作摸鱼两不误,知乎热门信息一网打尽
2019-04-29