设为首页 加入收藏

TOP

NYOJ-最高位数字
2015-07-20 17:46:53 来源: 作者: 【 】 浏览:3
Tags:NYOJ- 高位 数字

最高位数字

时间限制:1000 ms | 内存限制:65535 KB 难度:2
描述
求N^N的个位数字大家应该都会了,可是,N^N的最高位数字你会求吗?
输入
多组测试数据。
每组数据输入一个正整数N(N≤1,000,000,000)。
输出
对于每组数据,输出N^N的最高位数字。
样例输入
3
4
样例输出
2
2
代码:
#include
      
       
#include
       
         int main() { int n; double a; long long b; while(~scanf("%d",&n)) { a=n*log10(n)-(long long)(n*log10(n)); b=pow(10,a); printf("%lld\n",b); } return 0; }
       
      


解题思路:

n^n=a*10^t;(1

两边取对数得:nlogn=loga+t;

由:1

0

=>loga=nlogn-t

=>a=pow(10,loga)

=>最高位x=[a]


<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1966 Cable TV Network(无向.. 下一篇Codeforces 101B Buses 排序+树状..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)
·索引堆及其优化 - 菜 (2025-12-24 20:18:50)
·Shell 中各种括号的 (2025-12-24 19:50:39)
·Shell 变量 - 菜鸟教 (2025-12-24 19:50:37)