题目链接:uva 11549 - Calculator
Conundrum
题目大意:给出n和k,表示有一个n为的计算器,现在要计算k一直平方中的最大值(在计算器中出现的),超过n位取前n位。
解题思路:看队友题解上有一个判断说形成循环的条件a^2== b^4。然后模拟一下就可以了。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
ll k;
ll Pow(ll c) {
ll t = c * c;
char str[20];
sprintf(str, "%lld", t);
t = 0;
for (int i = 0; i < strlen(str) && i < n; i++)
t = t * 10 + str[i] - '0';
return t;
}
ll solve() {
ll a = k, b = k, ans = k;
while (true) {
a = Pow(a);
b = Pow(b); ans = max(ans, b);
b = Pow(b); ans = max(ans, b);
if (a == b) break;
}
return ans;
}
int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d%lld", &n, &k);
printf("%lld\n", solve());
}
return 0;
}
分享到:
相关推荐
GUI-Calculator,利用MATLAB-gui界面guide功能实现的计算器
argaret. Joy horrible moreover man feelings own shy. Request norland neither mistake for yet. Between the for morning assured country believe. On even feet time have an no at. Relation so in confined ...
react-native-nw-react-calculator, 移动桌面和网站应用具有相同的代码 移动,桌面和网站应用具有相同的代码 这个项目展示了如何在多个设备上运行源代码。 现在,它可以运行如下:iOS &应用( 基于响应本机插件)基于...
DRAM-Calculator-for-Ryzen
metric-bmi-calculator-app-using-python.zip
dutch-tax-income-calculator, 带AngularJS的荷兰税收收入计算器 dutch-tax-income-calculator带AngularJS的荷兰税收收入计算器你可以在这里测试- http://thetax.nl 。 更多关于税务括号的信息这里是:这里是( 用于 ...
S32K Flex memroy 模拟EEprom寿命计算器
资源来自pypi官网。 资源全名:ARC-Alkali-Rydberg-Calculator-2.1.2.tar.gz
solar-module-calculator.ods
income-tax-calculator-源码.rar
JS-Super-Calculator.html
Beam-Radiation-Calculator-master.zip
Circuit-Calculator-Make-Electronics.zip
MFC-calculator-master
Shopping-Change-Calculator-_NET-Core-Web-API-源码.rar
基于Qt Creator平台的UI 设计模式,先进行界面布局设计,再利用槽函数模板,适当编写C++程序,实现简易计算器。该GUI设计方法,充分利用Qt Creator平台的UI 设计模式,大大减少C++代码的编写,易于新手入门学习。...
Vue-Calculator-源码.rar
javascript-calculator-源码.rar
Laravel开发-delivery-calculator 通过提供开始日期时间和持续时间(小时)来计算日期时间
Laravel开发-calculator 测试包