HDU 1061 Rightmost Digit解决问题的方法
2024-10-18 13:24:57
求大量N^N的值最右边的数字,即最低位。
它将能够解决一个简单二分法。
只是要注意溢出,只要把N % 10之后。我不会溢出,代替使用的long long。
#include <stdio.h>
int rightMost(int n, int N)
{
if (n == 0) return 1;
int t = rightMost(n / 2, N);
t = t * t % 10;;
if (n % 2) t *= N;
return t % 10;
} int main()
{
int T, n;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
printf("%d\n", rightMost(n, n%10));
}
return 0;
}
版权声明:笔者靖心脏,景空间地址:http://blog.csdn.net/kenden23/。只有经过作者同意转载。
最新文章
- MongoDB可视化工具RoboMongo----Windows安装 1
- 二级缓存处理大数据 用ehcache.xml配置文件
- qml实现自定义标题栏按钮
- docker image export or import
- LoadRunner_Analysis(z) 分析
- [置顶] ruby变量详解(收集+整理)
- hdu3998 Sequence(最大流,LIS)
- android中viewPager实现的屏幕左右切换(入门篇)
- 修改cookie
- poj-1031-fence(不是我写的,我只是想看着方便)
- ubuntu如何安装 adobe flash player或adobe插件
- canvas绘图实现浏览器等待效果
- maven 下载源码downloadsources
- Oracle中的一些语句
- centos7上开启路由转发
- 【找规律】【DFS】Gym - 101174H - Pascal&#39;s Hyper-Pyramids
- spring boot+jaspersoft实现复杂报表
- hibernate中SQL包含冒号
- JS计算24节气的方法
- Long-term stable release maintenance