题目描述:

源码:

/**/
#include"iostream"
using namespace std; int main()
{
int t, mod;
long long n;
cin>>t;
for(int i = 0; i < t; i++)
{
cin>>n;
mod = n % 10;
if(mod == 0 || mod == 1 || mod == 5 || mod == 6)
{
cout<<mod<<endl;
}
else
{
switch(mod)
{
case 2:
mod = n % 4;
if(mod == 0)
{
cout<<6<<endl;
}
else if(mod == 1)
{
cout<<2<<endl;
}
else if(mod == 2)
{
cout<<4<<endl;
}
else
{
cout<<8<<endl;
}
break;
case 3:
mod = n % 4;
if(mod == 0)
{
cout<<1<<endl;
}
else if(mod == 1)
{
cout<<3<<endl;
}
else if(mod == 2)
{
cout<<9<<endl;
}
else
{
cout<<7<<endl;
}
break;
case 4:
if(n % 2 == 1)
{
cout<<4<<endl;
}
else
{
cout<<6<<endl;
}
break;
case 7:
mod = n % 4;
if(mod == 0)
{
cout<<1<<endl;
}
else if(mod == 1)
{
cout<<7<<endl;
}
else if(mod == 2)
{
cout<<9<<endl;
}
else
{
cout<<3<<endl;
}
break;
case 8:
mod = n % 4;
if(mod == 0)
{
cout<<6<<endl;
}
else if(mod == 1)
{
cout<<8<<endl;
}
else if(mod == 2)
{
cout<<4<<endl;
}
else
{
cout<<2<<endl;
}
break;
case 9:
if(n % 2 == 1)
{
cout<<9<<endl;
}
else
{
cout<<1<<endl;
}
break;
}
}
}
return 0;
}

  

HD-ACM算法专攻系列(2)——Rightmost Digit的更多相关文章

  1. HD-ACM算法专攻系列(19)——Leftmost Digit

    问题描述: AC源码: 解题关键是,数据很大,不能强算,需要使用技巧,这里使用科学计算法,令N^N=a*10^n ,取对数后变为 N*log10(N)=log10(a)+n,令x = log10(a) ...

  2. HD-ACM算法专攻系列(23)——Crixalis's Equipment

    题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的 ...

  3. HD-ACM算法专攻系列(21)——Wooden Sticks

    题目描述: AC源码: 此题考查贪心算法,解题思路:首先使用快速排序,以w或l按升序排序(注意相等时,应按另一值升序排序),这样就将二维变量比较,变为了一维的,排好序的一边就不需要去管了,只需要对未排 ...

  4. HD-ACM算法专攻系列(5)——N!

    题目描述: 源码: #include"iostream" using namespace std; int main() { int n, digit, carry, tmp; i ...

  5. HD-ACM算法专攻系列(22)——Max Sum

    问题描述: AC源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前i各之和为负数时,直接选择以第i+1个为开头,在于当前i各之和为正数时,第i个可以不用作为开头(因为前i+1个之和一定大于 ...

  6. HD-ACM算法专攻系列(20)——七夕节

    问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int mai ...

  7. HD-ACM算法专攻系列(18)——Largest prime factor

    题目描述: 源码: 需要注意,若使用cin,cout输入输出,会超时. #include"iostream" #include"memory.h" #defin ...

  8. HD-ACM算法专攻系列(17)——find your present (2)

    题目描述: 源码: #include"iostream" #include"string" using namespace std; bool IsFirstH ...

  9. HD-ACM算法专攻系列(16)——考试排名

    问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorith ...

随机推荐

  1. How to start/stop DB instance of Oracle under Linux

    All below actions should be executed with "oracle" user account 1. Check the status of lis ...

  2. MongoDB数据模型和索引学习总结

    MongoDB数据模型和索引学习总结 1. MongoDB数据模型: MongoDB数据存储结构: MongoDB针对文档(大文件採用GridFS协议)採用BSON(binary json,採用二进制 ...

  3. FreeRTOS系列第13篇---FreeRTOS内核控制

    内核控制的一些功能须要移植层提供,为了方便移植.这些API函数用宏来实现,比方上下文切换.进入和退出临界区.禁止和使能可屏蔽中断.内核控制函数还包含启动和停止调度器.挂起和恢复调度器以及用于低功耗模式 ...

  4. 智课雅思词汇---十二、vent是什么意思

    智课雅思词汇---十二.vent是什么意思 一.总结 一句话总结:词根:ven, vent = come, 表示“来” 词根:vent = wind 风 1.tact是什么意思? 词根:-tact-, ...

  5. SVG 贝塞尔曲线控制【方便设置】:贝塞尔曲线

    http://dayu.pw/svgcontrol/

  6. 简单的floyd——初学

     前言: (摘自https://www.cnblogs.com/aininot260/p/9388103.html): 在最短路问题中,如果我们面对的是稠密图(十分稠密的那种,比如说全连接图),计算多 ...

  7. 使用TensorBoard可视化工具

    title: 使用TensorBoard可视化工具 date: 2018-04-01 13:04:00 categories: deep learning tags: TensorFlow Tenso ...

  8. POJ 3048 线性筛法求素数

    一个坑: 有组数据如下: 1 1 坑很深-- //By SiriusRen #include <cstdio> #define N 200000 using namespace std; ...

  9. (转载) Android两个子线程之间通信

    Android两个子线程之间通信 标签: classthreadandroid子线程通信 2015-03-20 17:03 3239人阅读 评论(0) 收藏 举报  分类: 个人杂谈 版权声明:本文为 ...

  10. PostgreSQL 数据库性能调优的注意点

    PostgreSQL提供了一些性能调优的功能.主要有如下几个方面.1.使用EXPLAIN   EXPLAIN命令可以查看执行计划,这个方法是我们最主要的调试工具. 2.及时更新执行计划中使用的统计信息 ...