zoukankan      html  css  js  c++  java
  • B. Divisors of Two Integers

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Recently you have received two positive integer numbers xx and yy. You forgot them, but you remembered a shuffled list containing all divisors of xx (including 11 and xx) and all divisors of yy (including 11 and yy). If dd is a divisor of both numbers xx and yy at the same time, there are two occurrences of dd in the list.

    For example, if x=4x=4 and y=6y=6 then the given list can be any permutation of the list [1,2,4,1,2,3,6][1,2,4,1,2,3,6]. Some of the possible lists are: [1,1,2,4,6,3,2][1,1,2,4,6,3,2], [4,6,1,1,2,3,2][4,6,1,1,2,3,2] or [1,6,3,2,4,1,2][1,6,3,2,4,1,2].

    Your problem is to restore suitable positive integer numbers xx and yy that would yield the same list of divisors (possibly in different order).

    It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers xx and yy.

    Input

    The first line contains one integer nn (2n1282≤n≤128) — the number of divisors of xx and yy.

    The second line of the input contains nn integers d1,d2,,dnd1,d2,…,dn (1di1041≤di≤104), where didi is either divisor of xx or divisor of yy. If a number is divisor of both numbers xx and yy then there are two copies of this number in the list.

    Output

    Print two positive integer numbers xx and yy — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.

    Example
    input
    Copy
    10
    10 2 8 1 2 4 1 20 4 5
    
    output
    Copy
    20 8

    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define ll long long
    int a[10005],b[10005];
    int main()
    {
      int n,j=0;
      cin>>n;
      for(int i=0;i<n;i++)
      {
        cin>>a[i];
      }
      sort(a,a+n);
      cout<<a[n-1]<<" ";
      for(int i=1;i<=a[n-1];i++)
      {
        if(a[n-1]%i==0)
          {
            b[j]=i;
            j++;
          }
      }
      for(int k=0;k<j;k++)
      {
        for(int i=0;i<n;i++)
        {
          if(a[i]==b[k])
            {
              a[i]=1;
              break;
            }
        }
      }
      sort(a,a+n);
      cout<<a[n-1]<<endl;
    
      return 0;
    
    }
  • 相关阅读:
    day13_迭代器,生成器
    作业礼包
    day12_装饰器进阶
    装饰器作业
    day11_装饰器
    函数作业
    day10-函数进阶
    数据类型-习题解答
    day09_函数
    PHP 完美分页
  • 原文地址:https://www.cnblogs.com/-citywall123/p/10316513.html
Copyright © 2011-2022 走看看