题意翻译

给定一组有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=;i<=n;i++)
scanf("%d",&num[i]);
sort(num+,num++n);
for(int i=n;i>=;i--){
int k=sqrt(num[i]);
if(k*k!=num[i]){
cout<<num[i];
return ;
}
}
}

CF914A Perfect Squares的更多相关文章

  1. [LintCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  2. LeetCode Perfect Squares

    原题链接在这里:https://leetcode.com/problems/perfect-squares/ 题目: Given a positive integer n, find the leas ...

  3. Perfect Squares

    Perfect Squares Total Accepted: 18854 Total Submissions: 63048 Difficulty: Medium Given a positive i ...

  4. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  5. [LeetCode] 0279. Perfect Squares 完全平方数

    题目 Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9 ...

  6. LeetCode 279. 完全平方数(Perfect Squares) 7

    279. 完全平方数 279. Perfect Squares 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数 ...

  7. Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares)

    Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ar ...

  8. 花式求解 LeetCode 279题-Perfect Squares

    原文地址 https://www.jianshu.com/p/2925f4d7511b 迫于就业的压力,不得不先放下 iOS 开发的学习,开始走上漫漫刷题路. 今天我想聊聊 LeetCode 上的第2 ...

  9. [LeetCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

随机推荐

  1. SRM 621 D2L3: MixingColors, math

    题目:http://community.topcoder.com/stat? c=problem_statement&pm=10409&rd=15854 利用高斯消元求线性空间的基,也 ...

  2. [ajax 学习笔记] ajax初试

    ajax全称是:asynchronous javasctipt and xml. 1.为什么须要ajax? 一般web程序与server的交互是:页面发送请求等待server处理,server处理数据 ...

  3. 11gR2 Database Services for &quot;Policy&quot; and &quot;Administrator&quot; Managed Databases (文档 ID 1481647.1)

    In this Document   Purpose   _afrLoop=1459311711568804&id=1481647.1&displayIndex=6&_afrW ...

  4. HDU 1257(最小拦截系统)

    Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不 能超过前一发的高度.某天,雷达 ...

  5. BZOJ 3509 分块FFT

    思路: 跟今年WC的题几乎一样 (但是这道题有重 不能用bitset水过去) 正解:分块FFT http://blog.csdn.net/geotcbrl/article/details/506364 ...

  6. IO流读取文件内容时,出现空格的问题(未找到原因)

    import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOExceptio ...

  7. window 10 多版本激活工具

    window 10 通用版激活工具 云盘地址:https://pan.baidu.com/s/1bo3L4Kn 激活工具网站:http://www.tudoupe.com/win10/win10jih ...

  8. Java集合(一)HashMap

    HashMap 特点: HashMap的key和value都允许为空,无序的,且非线程安全的 数据结构: HashMap底层是一个数组,数组的每一项又都是链表,即数据和链表的结合体.当新建一个Hash ...

  9. mysql连接出现error node【1045】

    第一步:在my.ini下找到mysqlid.在后边添加skip-grant-tables 第二步:重新启动mysql服务 第三步:重新设置密码 第四步: 将skip-grant-tables删除掉,保 ...

  10. JavaScript实现网页换肤

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...