2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem
2024-08-31 09:00:49
2017-08-31 16:48:00
writer:pprp
这个题比较容易,我用的是快速幂
写了一次就过了
题目如下:
A Math Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
You are given a positive integer n, please count how many positive integers k satisfy k ^ k <= n
Input
There are no more than 50 test cases.
Each case only contains a positivse integer n in a line.
1≤n≤10^18
Output
For each test case, output an integer indicates the number of positive integers k satisfy k^k≤n in a line.
Sample Input
1
4
4
Sample Output
1
2
2
Input
There are no more than 50 test cases.
Each case only contains a positivse integer n in a line.
1≤n≤10^18
题目分析:
给你一个n,问你最大的 k ^ k <= n的 k的值,你可以用电脑上自带的计算器算一算,大概范围15^15就已经超过18位了,所以可以从15开始倒着枚举
代码如下:
#include <iostream> using namespace std;
typedef long long ll; //a ^ a
__int64 POW(ll a)
{
__int64 result = ;
ll base = a;
ll tmp = a;
while(tmp > )
{
if((tmp & ) == )
result = result * base;
base = base * base;
tmp >>= ;
}
return result;
} //int main()
//{
// ll a;
// cin >> a;
// cout << POW(a) << endl;
//
// return 0;
//} int main()
{
ios::sync_with_stdio(false);
__int64 n;
while(cin >> n)
{
for(int i = ; i >= ; i--)
{
if(POW(i) <= n)
{
cout << i << endl;
break;
}
}
}
return ;
}
最新文章
- tomcat 8在win8.1中的配置
- java提高篇(二)-----理解java的三大特性之继承
- android NDK 生成so 文件流程-ecplice
- Redis总结(三)Redis 的主从复制
- ibatis XML标签的含义
- asp.net中使用ueditor
- C#中的yield return与Unity中的Coroutine(协程)(上)
- jstl表达式替换某些字符
- POJ 3114 Countries in War(强联通分量+Tarjan)
- Can’t find file mysql/host.frm
- java SecurityManager
- Ext JS学习第四天 我们所熟悉的javascript(三)
- Windows编程坐标系统概念
- javascript 面向对象基础 (1)
- 《java入门第一季》之面向对象面试题(面向对象都做了哪些事情)
- Docker部署Nginx并修改配置文件
- Request获取客户端IP
- 逆袭之旅DAY.XIA.Object中常用方法
- FireDac 组件说明二
- [图解tensorflow源码] 入门准备工作附常用的矩阵计算工具[转]