Codeforces Round 1027 A. Square Year (2114)
本题地址
https://codeforces.com/contest/2114/problem/A
本题描述
解题思路:
根据以上,我们可以基本知道:2025=(20+25)*(20+25),但是后面描述,
只要(a+b)的平方=year即可,那就表示year是一个(数字+0)的平方值,
如此,一定存在,year的平方根,如果平方根的值的平方=year,就表示可以,否则-1
题目给的答案不是唯一的。
代码如下:
#include<iostream>
#include <string>
#include<math.h>
using namespace std;int main()
{int t;int n;cin >> t;for (int i = 0; i<t; i++){cin >> n;int sq = sqrt(n);// for : (a+b)*(a+b)==nif (sq*sq == n){cout << 0 << " " << sq << endl;}else{cout << -1 << endl;}}return 0;}
/*
Example
Input
5
0001
1001
1000
4900
2025Output
0 1
-1
-1
34 36
20 25
*/
参考其他人的代码,消化理解的,目前重在学习阶段。
本题大概能理解。