17110 Divisible(基础模运算)

本文介绍了一种解决特定整除问题的编程方法,利用了(a*b)%c=(a%c)*(b%c)%c的性质来简化计算过程,确保计算结果在限定范围内,适用于大整数的乘法和模运算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

17110 Divisible

时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: G++;GCC

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 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");
}
好像我这种做法是个玄学....


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值