首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【杭电oj】1060 - Leftmost Digit(数学好题)

【杭电oj】1060 - Leftmost Digit(数学好题)

作者头像
FishWang
发布2025-08-26 17:34:13
发布2025-08-26 17:34:13
10200
代码可运行
举报
运行总次数:0
代码可运行

Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15463    Accepted Submission(s): 6000 Problem Description

Given a positive integer N, you should output the leftmost digit of N^N.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single positive integer N(1<=N<=1,000,000,000).

Output

For each test case, you should output the leftmost digit of N^N.

Sample Input

代码语言:javascript
代码运行次数:0
运行
复制
2
3
4

Sample Output

代码语言:javascript
代码运行次数:0
运行
复制
2
2

Hint
In the first case, 3 * 3 * 3 = 27, so the leftmost digit is 2.
In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.

Author

Ignatius.L

巧用lg转化,下面是我用mathtype打出的解题过程:

另外注意,对x取整时应该用__int64,用int会越界,用long int时oj会判PE。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <stdio.h>
#include <math.h>
int main()
{
	int u;
	int ans;
	double num,a;
	double x;
	scanf("%d",&u);
	while(u--)
	{
		scanf("%lf",&num);
		x=num*log10(num);
		a=pow(10.0,x-(__int64)x);
		ans=int(a);
		printf("%d\n",ans);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Leftmost Digit
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档