CF914A Perfect Squares

题意翻译

给定一组有n个整数的数组a1,a2,…,an.找出这组数中的最大非完全平方数。 完全平方数是指有这样的一个数x,存在整数y,使得x=y^2y2 .

输入格式

第一行输入一个单独的整数n(1<=n<=1000 ),n为该组数的数量。 接下来有n个整数,a1,a2,an(-10^6<=a<=10^6) 数据保证至少存在一个整数是非完全平方数。

题目描述

Given an array a_{1},a_{2},...,a_{n}a1,a2,...,an of nn integers, find the largest number in the array that is not a perfect square.

A number xx is said to be a perfect square if there exists an integer yy such that x=y^{2}x=y2 .

输入输出格式

输入格式:

 

The first line contains a single integer nn ( 1<=n<=10001<=n<=1000 ) — the number of elements in the array.

The second line contains nn integers a_{1},a_{2},...,a_{n}a1,a2,...,an ( -10^{6}<=a_{i}<=10^{6}106<=ai<=106 ) — the elements of the array.

It is guaranteed that at least one element of the array is not a perfect square.

 

输出格式:

 

Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.

 

输入输出样例

输入样例#1: 复制
2
4 2
输出样例#1: 复制
2
输入样例#2: 复制
8
1 2 4 8 16 32 64 576
输出样例#2: 复制
32

说明

In the first sample case, 44 is a perfect square, so the largest number in the array that is not a perfect square is 22 .

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 1001
using namespace std;
int n;
int num[MAXN];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    sort(num+1,num+1+n);
    for(int i=n;i>=1;i--){
        int k=sqrt(num[i]);
        if(k*k!=num[i]){
            cout<<num[i];
            return 0;
        }
    }
}

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/8440585.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值