To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that the programs that work with fractions in this representations aren't complete, they lack supporting the operation of reducing fractions. Implement this operation and the Empire won't forget you.

Input

The first input line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) that show how many numbers the first set (the numerator) and the second set (the denominator) contain, correspondingly.

The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 107) — the numbers that are multiplied to produce the numerator.

The third line contains m space-separated integers: b1, b2, ..., bm (1 ≤ bi ≤ 107) — the numbers that are multiplied to produce the denominator.

Output

Print the answer to the problem in the form, similar to the form of the input data. The number of values in the sets you print nout, mout must satisfy the inequality 1 ≤ nout, mout ≤ 105, and the actual values in the sets aout, i and bout, i must satisfy the inequality 1 ≤ aout, i, bout, i ≤ 107.

Separate the values in the lines by spaces. The printed fraction must be reduced, that is, there mustn't be such integer x (x > 1), that the numerator and the denominator of the printed fraction are divisible by x. If there are several matching answers, print any of them.

Examples

Input
3 2
100 5 2
50 10
Output
2 3
2 1
1 1 1
Input
4 3
2 5 10 20
100 1 3
Output
1 1
20
3

Note

In the first test sample the numerator equals 1000, the denominator equals 500. If we reduce fraction 1000/500 by the greatest common divisor of the numerator and the denominator (by 500), we obtain fraction 2/1.

In the second test sample the numerator equals 2000, the denominator equals 300. If we reduce fraction 2000/300 by the greatest common divisor of the numerator and the denominator (by 100),

OJ-ID:
CodeForce 222C

author:
Caution_X

date of submission:
20191012

tags:
分解质因数

description modelling:
给出分子分母,求通分。(分子分母以一系列数的乘积给出)

major steps to solve it:
1.分别把分子分母分解质因数
2.通分

warnings:
分解质因数后有两种处理方案:
①:比较分解后分子分母的质因数,然后消去分子分母中相同的质因数(导致(溢出)WA和TLE)
②:用原来分子的乘积和分母的质因数相消,再用原来分母的乘积和分子的质因数相消
采用方案②

AC code:

#include<cstdio>
#include<cstring>
using namespace std;
int prime[]={};
int a[],b[];
int ap[],bp[];
void check(int *x,int *y,int len)//分解因子
{
for(int i=;i<len;++i)
for(int j=x[i];j>;j/=prime[j])
y[prime[j]]++;//因子数+1
}
void print(int *x,int *y,int len)
{
int cnt;
for(int i=;i<len;++i)
{
cnt=;
for(int j=x[i];j>;j/=prime[j])
if(y[prime[j]]>) y[prime[j]]--;
else cnt*=prime[j];
if(i==) printf("%d",cnt);
else printf(" %d",cnt);
}
puts("");
}
int main()
{
int n,m;
prime[]=;
for(int i=;i<=;++i)
if(!prime[i])
{
prime[i]=i;
for(int j=*i;j<=;j+=i)
prime[j]=i;
}
scanf("%d%d",&n,&m);
for(int i=;i<n;++i) scanf("%d",a+i);
for(int i=;i<m;++i) scanf("%d",b+i);
check(a,ap,n);check(b,bp,m);
printf("%d %d\n",n,m);
print(a,bp,n);print(b,ap,m);
return ;
}

CodeForce 222C Reducing Fractions的更多相关文章

  1. CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)

    ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...

  2. CF222C Reducing Fractions

    题目大意: 给出两个集合,第一个集合数的乘积是分子,第二个集合的数的乘积是分母,要求够造一个同样的集合,但是得到的分数是最简分数. 分析: 寻找思路并不复杂,对两个集合的每个数进行质因数分解,然后统计 ...

  3. ACM思维题训练 Section A

    题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...

  4. codeforces 练习

    codeforces 627 D. Preorder Test 二分 + 树dp 做logn次树dp codeforces 578D.LCS Again 给出一个字符串str,长度n<=10^6 ...

  5. Codeforces Round #137 (Div. 2)

    A. Shooshuns and Sequence 显然\([k,n]\)之间所有数均要相同,为了求最少步数,即最多模拟\(n\)次操作即可. B. Cosmic Tables 映射\(x_i,y_i ...

  6. CodeForce 359C Prime Number

    Prime Number CodeForces - 359C Simon has a prime number x and an array of non-negative integers a1,  ...

  7. Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)

    传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...

  8. Codeforces Round #232 (Div. 2) D. On Sum of Fractions

    D. On Sum of Fractions Let's assume that v(n) is the largest prime number, that does not exceed n; u ...

  9. 一天一经典Reducing the Dimensionality of Data with Neural Networks [Science2006]

    别看本文没有几页纸,本着把经典的文多读几遍的想法,把它彩印出来看,没想到效果很好,比在屏幕上看着舒服.若用蓝色的笔圈出重点,这篇文章中几乎要全蓝.字字珠玑. Reducing the Dimensio ...

随机推荐

  1. Drools规则引擎-如果Fact对象参数为null如何处理

    问题场景 在技术交流群(QQ:715840230)中有同学提出这样的问题: 往kiesession里面传入fact,如果不做输入检查fact里面有些字段可能是null值.但是如果在外面做输入检查,规则 ...

  2. DQL---条件查询、单行函数、多行函数、分组函数、数据类型

    一.DQL 1.基本规则: (1)对于日期型数据,做 *,/ 运算不合法,可以进行 +, - 运算.比如给日期加一天或减一个月,结果仍为一个日期.两个日期间只能为减法,返回两个日期相差的天数,两个日期 ...

  3. 作用域,作用域链,垃圾收集,js解析

    变量中包含基本数据类型和引用数据类型,基本类型指简单的数据值,引用类型由多个值构成的对象. 引用类型可以为其添加属性和方法,也可以改变和删除属性和方法. 复制变量值:     基本类型:一个变量向另一 ...

  4. ABP进阶教程5 - 多语言配置

    点这里进入ABP进阶教程目录 更新脚本 打开展示层(即JD.CRS.Web.Mvc)的\wwwroot\view-resources\Views\Course\Index.js //用以存放Cours ...

  5. 高并发高可、O2O、微服务架构用学习网站

    高并发高可.O2O.微服务架构用学习网站 https://www.itkc8.com 非常感谢http://www.cnblogs.com/skyblog/p/5044486.html 关于架构,笔者 ...

  6. CentOS服务器apache绑定多个域名的方法

    这篇文章主要为大家详细介绍了CentOS服务器apache绑定多个域名的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 Apache是最流行的HTTP服务器软件之一,其以快速.可靠(稳定) ...

  7. Shel脚本-初步入门之《06》

    Shel脚本-初步入门-06 Shell 脚本的建立和执行 6.Shell 脚本的建立和执行 6.1 Shell脚本的建立 在 Linux 系统中,Shell 脚本(bash Shell 程序)通常是 ...

  8. 3.Python网络编程_多任务问题抛出

    #单线程程序 import time def sing(): """唱歌5秒钟""" for i in range(5): print(&q ...

  9. Html学习之三(列表)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. 关于destoon6.0下的ngnix伪静态

    关于destoon6.0下的ngnix伪静态配置 ##rewrite nginx rewrite '(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)' ...