hdu 1061 - Rightmost Digit(求N^N末位)

Given a positive integer N, you should output the most right digit of N^N. Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N. InputThe input contains several test cases. The first line of the input is a single integer T which is the... 阅读详情


Rightmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24345    Accepted Submission(s): 9291


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 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.


=======================


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int m=n%10;//n的个位
        int ans=m,a,flag=0;
        for(int i=1;i<n;i++)
        {
            ans=ans*m%10;
            if(ans==m)
            {
                a=i;//循环节
                ans=1;
                flag=1;
                //cout<<a<<"------"<<endl;
                break;
            }
        }
        if(flag==1)
        for(int i=0;i<=(n-1)%a;i++)
        {
            ans=(ans*m)%10;
        }
        cout<<ans<<endl;
    }
    return 0;
}

工业相机图像格式深度解析:从Mono8到Mono12的选型与应用 本文深度解析工业相机黑白图像格式,重点对比Mono8、Mono10与Mono12的核心差异。文章从位深、动态范围和数据量等关键概念切入,详细阐述了不同格式的优缺点及适用场景,为工业视觉项目中的相机选型提供实战指南,帮助用户在精度、速度与成本间做出最优决策。 阅读详情

相关推荐

CANoe基础讲解01:从零开始使用CANoe轻松搭建你的第一个CAN网络

本文是一篇CANoe软件入门实操指南,逐步演示了如何从零创建并运行一个CAN FD仿真工程。内容包括:启动软件、配置硬件通道与网络、加载DBC数据库、使用CAPL编写仿真节点发送CAN报文,最终启动测量并在Trace窗口中查看通信结果。通过七个清晰步骤,帮助初学者快速掌握CANoe基本操作,完成首个可运行的仿真网络搭建

车载网络小D的博客 1573

HDU - 1061 Rightmost Digit (找规律/快速幂)

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 ca...

洛 水 290

PCA9548实战:从硬件连接到Linux驱动的I2C扩展全解析

本文详细解析了PCA9548 I2C多路复用器从硬件连接到Linux驱动配置的全过程。涵盖硬件引脚连接、电源去耦、地址选择等关键设计要点,以及Linux驱动加载、设备树配置和应用层编程技巧,帮助开发者高效实现I2C总线扩展。

weixin_28726391的博客 410

HDU - 1061 -Rightmost Digit (幂取模,白书)

Rightmost Digit 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 t

bobo 577

Marin说PCB之LPDDR5的布线注意事项--01

以上就是本期所有内容了,有些是通用的LPDDR5的设计准则,有的是针对单板的设计规则,严格意义说是没有哪一种规则是完全适用的LPDDR5的 通用规则的,不同的单板可能板厚,板材,层数,SOC以及DDR的型号都是不同的,一般的做法就是严格按照SOC手册上的LPDDR5的要求加上仿真同事给的建议修改优化就好了,我们下期文章不见不散。我们知道想要做好一个LPDDR颗粒,需要考虑的是因素有很多例如,电源完整性,信号完整性,层叠的设计,布局的摆放,布线的合理规划,去耦电容的摆放等等。

weixin_45223454的博客 3163

LEF文件介绍及其生成

介绍LEF文件及其生成方法

weixin_43249158的博客 3万+

HDOJ-1061-Rightmost Digit (求n^n的最低位)

/*Rightmost DigitTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6515    Accepted Submission(s): 2454Problem DescriptionGiven a posi

轻疯 清风 8387

AI 赋能 DBA:如何用 DeepSeek 等大模型简化数据库管理工作

数据库管理员(DBA)的工作涉及 SQL 优化、故障排查、性能监控等复杂任务。而 DeepSeek、ChatGPT 等大模型可以大幅减少重复劳动,提高 DBA 的工作效率。:某电商平台的订单查询 SQL 执行缓慢(平均 5s),DBA 需要优化。:DBA 需要监控 MySQL 的慢查询,但不想手动写脚本。:某金融系统频繁出现数据库死锁,DBA 需要快速定位原因。:大模型可分析 SQL 执行计划,推荐索引优化方案。:用日常语言查询数据库,无需写复杂 SQL。:一键生成监控、备份、数据迁移脚本。

专注于编程、AI、人工智能等多个领域内容研究和分析 565

G - Problem G-求n的n次方结果最右边数字

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 ca...

weixin_43999137的博客 1176

学Simulink——基于 Simulink 的 滑模控制(SMC)

本文详细介绍了基于Simulink的Buck变换器滑模控制(SMC)设计与实现方法。首先阐述了传统PI控制在负载突变时的不足,以及滑模控制具有强鲁棒性和快速响应的优势。通过建立Buck变换器的连续状态方程,推导了含积分项的滑模面和控制律,并采用边界层法抑制抖振。文章分步骤讲解了Simulink模型搭建过程,包括主电路、控制器实现和负载扰动模拟模块。仿真结果表明,在负载1A↔5A阶跃时,SMC控制输出电压波动仅0.08V,恢复时间0.35ms,远优于传统PI控制。同时给出了工程实践中的参数选择建议和数字实现技

amy_mhd的博客 254

华为od 面试八股文_C++_02_含答案

华为od 面试八股文_C++_02_含答案

MISAYAONE的博客 3121

HDU OJ1061 Rightmost Digit

HDU OJ1061 Rightmost DigitProblem 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 s

星琳之梦的博客 500

车载网络测试实操源码_使用CAPL脚本进行UDS刷写及其自动化测试

本文主要讲解如何使用CAPL脚本进行UDS刷写及其自动化测试,并结合了几个测试实例进行介绍,希望对大家有所帮助。

文章主要涉及嵌入式软件开发、测试、项目管理等,欢迎交流,共同进步。 1552

HDU 1061 Rightmost Digit题解

求一个大数N^N的值的最右边的数字,即最低位数字。 简单二分法求解就可以了。 不过注意会溢出,只要把N % 10之后,就不会溢出了,不用使用long long。 #include int rightMost(int n, int N) { if (n == 0) return 1; int t = rightMost(n / 2, N); t = t * t % 10;;

靖空间 969

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU 1061 Rightmost Digit

 Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N.  InputThe input contains several test cases. The first line of the input is a single integer

Czy 2043

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

HDU 1061 Rightmost Digit

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19450    Accepted Submission(s): 7504 Problem Description Given a p

胖子加油! 262

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【HDU-oj】-1061-Rightmost Digit(快速幂)

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 47443    Accepted Submission(s): 17915 Problem Description Given a

Bear1998的博客 502

Rightmost Digit HDU--1061

利用快速幂的方法 求出N^N,在每一次乘和的时候  对10取余得到的答案就是最后的一位数了。 #include #include int rightD(int n) { int ans=1; int a=n,b=n; a%=10; while(b) { if(b%2==1) { ans*=a

其实我是C先生--的博客 635

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

G_rass的专栏 417

HDU-1061-Rightmost Digit,快速幂水过!~~

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) http://acm.hdu.edu.cn/showproblem.php?pid=1061 Problem Description Given a positive inte

NYIST_TC_LYQ的博客 759

hdu1061 Rightmost Digit 快速幂的简单应用

**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

loving coding 375

HDU-1061-Rightmost Digit【快速幂】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1061 Rightmost Digit Problem Description Given a positive integer N, you should output the most right digit of N^N.   Input

Mongo_girl 274

Hdu 1061 Rightmost Digit

Rightmost DigitTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 55989    Accepted Submission(s): 21157Problem DescriptionGiven a positive integer...

你身后的人 142
上一篇: hdu 1060 - Leftmost Digit(求N^N最高位)
下一篇: hdu 2050 - 折线分割平面
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值