题目链接:http://codeforces.com/contest/583/problem/C

C. GCD Table
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The GCD table G of size n × n for an array of positive integers a of length n is defined by formula

Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both xand y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:

Given all the numbers of the GCD table G, restore array a.

Input

The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.

All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.

Output

In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.

Examples
input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
output
4 3 6 2
input
1
42
output
42 
input
2
1 1 1 1
output
1 1 

题意:你有n个数,给你n个数相互的gcd,即 gcd(a[i],a[j]) 1<=i<=n ,1<=j<=n;

    让你求原来n个数 a[i],随意输出;

思路:首先,发现对称,好像没有什么用;

   显然gcd只可能变小对吧,所以我们取最大的那个是必然存在的,放入a组数中,然后继续找下一个;

   记得删掉取得数,和取数之间的gcd即可;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define mk make_pair
#define eps 1e-7
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e4+,M=4e6+,inf=;
const ll INF=1e18+,mod=; /// 数组大小
map<int,int>mp;
map<int,int>::iterator it;
vector<int>ans;
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n*n;i++)
{
int x;
scanf("%d",&x);
mp[x]++;
}
for(int i=;i<=n;i++)
{
it=--mp.end();
int z=it->first;
for(int j=;j<ans.size();j++)
{
int g=__gcd(z,ans[j]);
mp[g]--;
mp[g]--;
if(!mp[g])mp.erase(mp.find(g));
}
ans.push_back(z);
mp[z]--;
if(!mp[z])mp.erase(mp.find(z));
}
for(int i=;i<n;i++)
cout<<ans[i]<<" ";
return ;
}

   

Codeforces Round #323 (Div. 2) C. GCD Table map的更多相关文章

  1. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  2. Codeforces Round #323 (Div. 2) C.GCD Table

    C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...

  3. Codeforces Round #323 (Div. 1) A. GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)

    对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i] ...

  5. Codeforces Round #323 (Div. 2) C 无敌gcd 数学/贪心

    C. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #323 (Div. 2)

    被进爷坑了,第二天的比赛改到了12点 水 A - Asphalting Roads /************************************************ * Author ...

  7. Codeforces Round #140 (Div. 1) D. The table 构造

    D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...

  8. Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题

    A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...

  9. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

随机推荐

  1. 版本 ------- 2017年最受开发者欢迎的10个Linux发行版

    1.Arch Linux Arch Linux在安装过程中提供了强大的可定制选择,支持你下载和安装自己所需的程序包.虽然这个选择对新手来说没有多大的帮助,但是它确实能够帮助那些使用Arch构建系统和存 ...

  2. window7 触屏操作相关

    一.体系概述 1.Windows Touch Input 和 Gestures消息 Windows Touch消息特性 通过在执行期间的监听和解释来使能.下面的示例展示了Windows7 上消息是怎么 ...

  3. STA分析(七) sdc

    STA分析前的环境设置,包括:setup clocks,specifying IO characteristics 1)定义一个master clock:create_clock -name .. - ...

  4. 54. Spiral Matrix(剑指offer--19)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  5. mysql_connect

    in this passage, we slove the problem about Mysql_connect. first, let' see an example: resource mysq ...

  6. python 元组 序列上使用enumerate()函数

    不能直接for n,x,y in enumerate(data)

  7. 彻底明白Flink系统学习5:window、Linux本地安装Flink

    http://www.aboutyun.com/thread-26393-1-1.html 问题导读 1.如何在window下安装Flink? 2.Flink本地安装启动命令与原先版本有什么区别? 3 ...

  8. Java SE 基础知识(String,Array)

    String 类: 1. 对于String对象的相等性判断来说,请使用equals()方法,而不是==.String的equals()是判断当前字符串与传进来的字符串的内容是否一致. 2. Strin ...

  9. 访问Hsql .data数据库文件

    一.Hsql简介: hsql数据库是一款纯Java编写的免费数据库,许可是BSD-style的协议. 仅一个hsqldb.jar文件就包括了数据库引擎,数据库驱动,还有其他用户界面操作等内容.下载地址 ...

  10. dom4j解析xml报"文档中根元素后面的标记格式必须正确"

    今天,在写个批量启动报盘机的自动化应用,为了简化起见,将配置信息存储在xml中,格式如下: <?xml version="1.0" encoding="UTF-8& ...