求大量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/。只有经过作者同意转载。

最新文章

  1. MongoDB可视化工具RoboMongo----Windows安装 1
  2. 二级缓存处理大数据 用ehcache.xml配置文件
  3. qml实现自定义标题栏按钮
  4. docker image export or import
  5. LoadRunner_Analysis(z) 分析
  6. [置顶] ruby变量详解(收集+整理)
  7. hdu3998 Sequence(最大流,LIS)
  8. android中viewPager实现的屏幕左右切换(入门篇)
  9. 修改cookie
  10. poj-1031-fence(不是我写的,我只是想看着方便)
  11. ubuntu如何安装 adobe flash player或adobe插件
  12. canvas绘图实现浏览器等待效果
  13. maven 下载源码downloadsources
  14. Oracle中的一些语句
  15. centos7上开启路由转发
  16. 【找规律】【DFS】Gym - 101174H - Pascal&#39;s Hyper-Pyramids
  17. spring boot+jaspersoft实现复杂报表
  18. hibernate中SQL包含冒号
  19. JS计算24节气的方法
  20. Long-term stable release maintenance

热门文章

  1. ssh 即使主机,同nohup背景脚本
  2. c4Droid
  3. 西南民大oj(两园交求面积)
  4. UVA 5875 DP
  5. Jndi使用好处,与简单实例【JBOSS】
  6. Windows下文件或文件夹不能删除时的解决办法
  7. There is no Action mapped for namespace / and action name UserAction
  8. Git在下搭建下环境的工具
  9. Redhat 6.3中syslog信息丢失
  10. PowerDesigner 对 Oracle 作 逆向工程