17110 Divisible(basic)
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
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 typedef long long ll; 5 ll I[110],T[110]; 6 7 ll gcd(ll a,ll b) 8 { 9 return b==0?a:gcd(b,a%b); 10 } 11 12 int main() 13 { 14 int n, m; 15 cin>>n>>m; 16 for(int i = 0; i < n; ++i) { 17 cin>>I[i]; 18 } 19 for(int i = 0; i < m; ++i) { 20 cin>>T[i]; 21 } 22 23 int i; 24 for(i = 0;i < m ; i++){ 25 for(int j = 0; j < n && T[i] != 1; j++){ 26 if(I[i]==1) continue; 27 ll g=gcd(I[j],T[i]); 28 I[j] /= g; 29 T[i] /= g; 30 } 31 if(T[i] != 1) break;//发现一个T[i]不能被I[0]*I[1]*…*I[n]整除,则跳出循环输出no 32 } 33 if(i < m) cout<<"no"; 34 else cout<<"yes"; 35 return 0; 36 }