ACM — Rightmost Digit

智码鎏金引
• 阅读 2449

题目链接

http://acm.hdu.edu.cn/showpro...

完整源码

#include <stdio.h>
#include <math.h>

int main() {
    int a[10] = {1, 1, 4, 4, 2, 1, 1, 4, 4, 2};
    int n, num, rmd, ans; // rmd = rightmost digit
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &num);
        rmd = num % 10;
        ans = (int) pow(rmd, num % a[rmd] ? num % a[rmd] : a[rmd]);
        printf("%d\n", ans % 10);
    }
}

简单解释

int a[10] = {1, 1, 4, 4, 2, 1, 1, 4, 4, 2}

个位为0的数字,1次为循环节;
个位为1的数字,1次为循环节;
个位为2的数字,4次为循环节;
以此类推。

ans = (int) pow(rmd, num % a[rmd] ? num % a[rmd] : a[rmd]);

个位是rmd,需要做num % a[rmd]次运算,但如果num % a[rmd]为0则不对,因此用问号表达式处理为0的情况。

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Stella981 Stella981
3年前
2019 HDOJ Multi
服务器时不时爆炸,有点难受。题目链接:http://acm.hdu.edu.cn/userloginex.php?cid849(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fuserloginex.php%3Fcid%3D849)
Wesley13 Wesley13
3年前
2018年全国多校算法寒假训练营练习比赛(第一场)G 圆圈
链接:https://www.nowcoder.com/acm/contest/67/G(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.nowcoder.com%2Facm%2Fcontest%2F67%2FG)来源:牛客网时间限制:C/C1秒,其他语
Wesley13 Wesley13
3年前
2019 ACM
题目链接:Lightbulbs(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fnanti.jisuanke.com%2Ft%2F41399)比赛链接:ThePreliminaryContestforICPCAsiaShanghai2019(https://www.
可莉 可莉
3年前
2021年全球公有云终端用户支出将增长18% ;EMNLP 2020最佳论文:无声语音的数字发声
!(https://static001.geekbang.org/infoq/af/af9f6637b50b09be60b00a42f3812d5e.png)开发者社区技术周刊又和大家见面
Stella981 Stella981
3年前
2021年全球公有云终端用户支出将增长18% ;EMNLP 2020最佳论文:无声语音的数字发声
!(https://static001.geekbang.org/infoq/af/af9f6637b50b09be60b00a42f3812d5e.png)开发者社区技术周刊又和大家见面
Wesley13 Wesley13
3年前
ACM
学长写的F.FantasticGraph"Oh,Thereisabipartitegraph.""MakeitFantastic."Xwantstocheckwhetherabipartitegraphisafantasticgraph.Hehastwofantasticnumbers,andh
可莉 可莉
3年前
2019 HDOJ Multi
服务器时不时爆炸,有点难受。题目链接:http://acm.hdu.edu.cn/userloginex.php?cid849(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fuserloginex.php%3Fcid%3D849)
Stella981 Stella981
3年前
AI 科学家带你快速 Get 人工智能最热技术
!(https://pic3.zhimg.com/80/v2af9f6637b50b09be60b00a42f3812d5e_1440w.jpg)日前,京东智联云与贪心学院联合举办的人工智能前沿技
Wesley13 Wesley13
3年前
Java大数统计
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid1316(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fshowproblem.php%3Fpid%3D1316)题目描述:!(https://o
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(