首页 > 其他 > 详细

17110 Divisible(basic)

时间:2014-02-18 09:22:27      阅读:298      评论:0      收藏:0      [点我收藏+]

17110 Divisible

时间限制:1000MS  内存限制:65535K

题型: 编程题   语言: 无限制

Description

Given n + m integers, I1,I2,...,In,T1,T2,...,Tm, we want to know whether (I1*I2*...*In)%(T1*T2*...*Tm)= =0.

输入格式

The first line gives two integers n and m. 1<=n,m<=100

The second line gives n integers I1 I2 ... In.

The third line gives m integers T1 T2 ... Tn.

1<=Ii, Ti<=231

输出格式

Satisfy (I1*I2*...*In)%(T1*T2*...*Tm)= =0, output "yes", otherwise output "no"

输入样例

2 3
24 14
2 7 3

输出样例

yes
 
#include <iostream>

using namespace std;
typedef long long ll;
ll I[110],T[110];

ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

int main()
{
    int m,n,i,j;
    cin>>n>>m;
    for(i=0;i<n;i++)
        cin>>I[i];
    for(i=0;i<m;i++)
        cin>>T[i];

    for(i=0;i<m;i++)
    {
        for(j=0;j<n&&T[i]!=1;j++)
        {
            if(I[i]==1) continue;
            ll tmp=gcd(I[j],T[i]);
            I[j]/=tmp;
            T[i]/=tmp;
        }
        if(T[i]!=1) break;//发现一个T[i]不能被I[0]*I[1]*…*I[n]整除,则跳出循环输出no
    }
    if(i<m) cout<<"no";
    else cout<<"yes";
    return 0;
}

17110 Divisible(basic)

原文:http://www.cnblogs.com/zyx1314/p/3553049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!