信息数学-唯一分解定理
信息数学-唯一分解定理
[NOIP2009 提高组] Hankson 的趣味题
https://www.bilibili.com/video/BV1Uc411h7Yq?spm_id_from=333.337.search-card.all.click
https://www.bilibili.com/video/av969414179/
https://www.luogu.com.cn/problem/P1072
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 50010;
int primes[N], cnt;
bool st[N];
struct Factor{
int p, s;
}factor[10];
int fcnt;
int dividor[1601], dcnt;
void init(int n){
for (int i = 2; i <= n; i ++ ){
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] * i <= n; j ++ ){
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
void dfs(int u, int p){
if (u == fcnt){
dividor[dcnt ++ ] = p;
return;
}
for (int i = 0; i <= factor[u].s; i ++ ){
dfs(u + 1, p);
p *= factor[u].p;
}
}
int gcd(int a, int b){
return b ? gcd(b, a % b) : a;
}
int main(){
init(N - 1);
int n;
cin >> n;
while (n -- ){
int a, b, c, d;
cin >> a >> b >> c >> d;
fcnt = 0;
int t = d;
for (int i = 0; primes[i] <= t / primes[i]; i ++ ){
int p = primes[i];
if (t % p == 0){
int s = 0;
while (t % p == 0) t /= p, s ++ ;
factor[fcnt ++ ] = {p, s};
}
}
if (t > 1) factor[fcnt ++ ] = {t, 1};
dcnt = 0;
dfs(0, 1);
int res = 0;
for (int i = 0; i < dcnt; i ++ ){
int x = dividor[i];
if (gcd(a, x) == b && (LL)c * x / gcd(c, x) == d) res ++ ;
}
cout << res << endl;
}
return 0;
}
信奥中的数学:唯一分解定理
https://blog.csdn.net/dllglvzhenfeng/article/details/122989701
质因数(唯一)分解定理第1讲
https://www.bilibili.com/video/BV1ag4y1v7YP?spm_id_from=333.999.0.0
质因数(唯一)分解定理第2讲
https://www.bilibili.com/video/BV1sg4y1v7SW?spm_id_from=333.999.0.0
质因数(唯一)分解定理第3讲
https://www.bilibili.com/video/BV1mT4y1J73X?spm_id_from=333.999.0.0
质因数(唯一)分解定理第4讲
https://www.bilibili.com/video/BV1aA411i7MC?spm_id_from=333.999.0.0
例题:
1.在1-200之间有几个数,其所有不同的素因数之和为16(比如:12的所有不同的素因数为2,3,其和为2+3=5)
6个数
分析:
16=11+3+2,11×2×3=66,11×2×3×2=132,11×2×3×3=198
16=11+5,11×5=55
16=13+3,13×3=39,13×3×3=117
所以:在1-200之间有66、132、198、55、39、117共有6个数,其所有不同的素因数之和为16
作者:newcode 更多资源请关注纽扣编程微信公众号

从事机器人比赛、机器人等级考试、少儿scratch编程、信息学奥赛等研究学习

浙公网安备 33010602011771号