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;
    
    }
  • 相关阅读:
    线性代数学习笔记(代数版)
    洛谷P2765 魔术球问题(贪心 最大流)
    洛谷P2770 航空路线问题(费用流)
    洛谷P4013 数字梯形问题(费用流)
    洛谷P2774 方格取数问题(最小割)
    洛谷P2761 软件补丁问题(状压DP,SPFA)
    项目mysql数据导入数据的Java程序
    axd与ashx区别
    LD1-K(求差值最小的生成树)
    rabbitMQ入门
  • 原文地址:https://www.cnblogs.com/-citywall123/p/10316513.html
Copyright © 2011-2022 走看看