hdu 1060 Leftmost Digit
2023-04-18 12:33:55 时间
一句话题意:让你求n^n的最左位的数字是多少。
题解:n最大可以为1000000000,那n^n就是超大的数了,,对于求关于n次方、斐波那契额和阶乘的位数这类的问题,首先就会想到取对数什么的(套路...);那么,看这题,对于m=n^n,有log10(m)=n*log10(n); 假设log10(m)=X.abcd,n^n=H.efgh*10^y;那么,又因为10^X.abcd=m=H.efgh*10^y; 则必有:X=H;故:10^0.abcd=H.efgh;求出10^0.abcd后,那它的整数位就是n^n的最左位了。 (另外,在对double取整时用(int)强转时会一直莫名的wa...估计应该是double为64位、int为32位互相转换损失的精度在某些数据上会给坑。。。)
ac代码:
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 #include <cmath> 6 #include <set> 7 #include <utility> 8 #include <vector> 9 #include <map> 10 #include <queue> 11 #include <stack> 12 const int inf=0x3f3f3f3f; 13 const double PI=acos(-1.0); 14 const double EPS=1e-8; 15 using namespace std; 16 typedef long long ll; 17 typedef pair<int,int> P; 18 19 void debug() 20 { 21 } 22 int n; 23 int main() 24 { 25 //freopen("input.txt","r",stdin); 26 //debug(); 27 int T; 28 scanf("%d",&T); 29 while(T--) 30 { 31 scanf("%d",&n); 32 double temp=(double)n*log10((double)n); 33 //temp-=(int)temp; 34 temp-=(ll)temp; // 35 double tt=pow(10.0,temp); 36 int ans=(int)tt; 37 cout<<ans<<endl; 38 } 39 return 0; 40 }
相关文章
- 微软大中华区BizSpark创新企业大赛扬帆起航
- Window-wsl2-emacs与Windows程序文件I/O卡顿延迟问题
- TeLOS Linux,基于 Debian 的全新 Linux 发行版
- Linux 基金会宣布 Rend-o-matic 加入 Call for Code 列表
- 系统分析师:商业智能和业务流程管理的集成分析
- 鸿蒙Hi3516如何连接WiFi(一)
- Windows 10 太阳谷更新界面猜想:圆角弹窗,开始菜单可居中显示
- 如何加大IRPStackSize以改善Windows 10中的网络速度?
- 为什么航天器、导弹喜欢用单片机,而不是嵌入式系统?
- Windows10下发新补丁:修复蓝屏、打印机抽风等问题
- 在 Linux 上使用 gImageReader 从图像和 PDF 中提取文本
- Linux Kernel 5.12第3个候选版本更新发布:正式版4月底发布
- 微软 Edge 将采用与 Chrome 相同的四周更新计划
- 已存在 15 年之久的 Linux 内核漏洞让攻击者获得 Root 权限
- 戴尔携手Teradata 构建商业智能基础
- 在Linux中如何将Nautilus文件管理器与Git集成
- 如何优雅的给Docker配置网络代理
- 鸿蒙内核源码分析(寄存器篇) | ARM37个寄存器一网打尽, 不再神秘
- Windows 10的这些浏览器都不能用了
- 微软 Edge 浏览器正在获得全新颜色选择器和主题选项