17110 Divisible时间限制:1000MS 内存限制:65535K 题型: 编程题 语言: G++;GCC DescriptionGiven 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 324 142 7 3 输出样例yes 作者admin |
我用的的是(a*b)%c=(a%c)*(b%c)%c,因为a,b都是比较大的整数,通过这样化简能够保证出来的值一定在0-c-1之间,
我是分开求两段,题目要求是否整除,先求前面一段sum1=l1*l2..*ln ==== sum1=(l1%c)*(l2%c)%c*....(ln%c)%c
同理sum2就是后面那一段t1*t2..*tm,然后根据sum1%sum2==0,判断是否能整除
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <string>
#include <bitset>
#define c 1000000007
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
using namespace std;
int main()
{
int n,m;
long long sum1,sum2,a;
sum1=1;
sum2=1;
scanf("%d%d",&n,&m);
while(n--)
{
scanf("%lld",&a);
sum1=(sum1%c)*(a%c)%c;
// printf("%lld\n",sum1);
}
while(m--)
{
scanf("%lld",&a);
sum2=(sum2%c)*(a%c)%c;
// printf("%lld\n",sum2);
}
// printf("%lld %lld\n",sum1,sum2);
if(sum1%sum2==0) printf("yes\n");
else printf("no\n");
}
好像我这种做法是个玄学....