【SCAU 13校赛】 17110 Divisible 唯一分解定理 or 同余定理

博客详细介绍了如何利用唯一分解定理解决一道关于同余定理的问题。作者指出,尽管通解是同余定理,但通过唯一分解定理同样可以得出答案。文章阐述了问题的关键在于比较分子和分母中质因数的个数,确保分子中每个质因数的出现次数大于或等于分母中对应的次数,以实现整除。最后,博主提供了AC代码实现。
摘要由CSDN通过智能技术生成

Description
Given n + m integers, I1,I2,…,In,T1,T2,…,Tm, we want to know whether (I1I2In)%(T1T2*…*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 (I1I2In)%(T1T2*…*Tm)= =0, output “yes”, otherwise output “no”

输入样例
2 3
24 14
2 7 3

输出样例
yes

题意:问两个数组分别累乘后前者能否整除后者

思路(唯一分解定理):

写完发现这个题的通解是同余定理。但是用唯一分解定理也能做,看到没人写这个方法的博客,我就记录一下。
首先,这个题莽夫做法累乘肯定是不行的。毕竟数据范围摆在那里。
观察发现,你一个分式要整除,那么分子分母分解成质数相乘的结果后,对应每个数分子有的,分母也要有,且分子的这个数的个数还要更多一点,才能整除。举个例子
求5x10x6 % 5x2x3时=>(5x10x6) /(5x2x3)=>(5x2x5x2x3)/(5x2x3),这样就可以约分了,把相同的约掉,只剩下分子5x2=10,整除。
转化为代码就是分别统计分子分母出现的质因数个数,然后逐个判断含有的质因数个数是否相等、若相等再判断每个质因数的出现个数能不能满足分母中的小于分子中的。

AC代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 5e5+2;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值