HDU4497 GCD and LCM 如果 \(G \% L != 0\) ,那么输出 \(0\) . 否则我们有 \(L/G=(p_1^{r_1})\cdot(p_2^{r_2})\cdot(p_3^{r_3})\cdots(p_m^{r_m})\) . 我们又有: \[ x=(p_1^{i_1})\cdot(p_2^{i_2})\cdot(p_3^{i_3})\cdots(p_m^{i_m}) \\ y=(p_1^{j_1})\cdot(p_2^{j_2})\cdot(p_3^{j_3})…
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 78 Accepted Submission(s): 43 Problem Description Given two positive integers G and L, could you tell me how many solutions of (x, y, z)…
这个题目挺不错的,看到是通化邀请赛的题目,是一个很综合的数论题目. 是这样的,给你三个数的GCD和LCM,现在要你求出这三个数有多少种可能的情况. 对于是否存在这个问题,直接看 LCM%GCD是否为0,如果不为0的话,就没有满足条件的数哦,反之一定有. 接下来问题等价于求三个数GCD为1,LCM为LCM/GCD的种类数了. 设这个商为X. 首先我们可以把X因数分解成X=(p1*x1)*(p2*x2)*……*(pn*xn): 单独拿出一个素数进行讨论,如果要设ABC分别为满足情况的三个数,那么Xa…
题意:三个数x, y, z. 给出最大公倍数g和最小公约数l.求满足条件的x,y,z有多少组. 题解:设n=g/l n=p1^n1*p2^n2...pn^nk (分解质因数 那么x = p1^x1 * p2^x2 * .... ^ pn^xk y = p1^y1 * p2^y2 * .... ^ pn^yk x = p1^z1 * p2^z2 * .... ^ pn^zk 那么对于任意i (0<=i<=k) 都有 min(xi, yi, zi) = 0, max(xi, yi, zi) = n…
link:http://acm.hdu.edu.cn/showproblem.php?pid=4497 如果G%L != 0,说明一定无解. 把K = G / L质数分解,G / L = p1^t1 * p2^t2 * p3^t3 * ……:同时 x/= L, y/= L, z/=L,不影响结果. 假设三个数字的质数分解是: x = p1^i1 * p2^i2 * p3^i3 * …… y = p1^j1 * p2^j2 * p3^j3 * …… z = p1^k1 * p2^k2 * p3^k…
CF EDU 1101D GCD Counting 题意 有一颗树,每个节点有一个值,问树上最长链的长度,要求链上的每个节点的GCD值大于1. 思路 由于每个数的质因子很少,题目的数据200000<2*3*5*7*11*13*17=510510.所以每个节点的质因子个数不多.那么树形DP的时候直接枚举每种因子即可. //#pragma GCC optimize(3) //#pragma comment(linker, "/STACK:102400000,102400000") /…
并不重要的前言 最近学习了一些数论知识,但是自己都不懂自己到底学了些什么qwq,在这里把知识一并总结起来. 也不是很难的gcd和lcm 显而易见的结论: 为什么呢? 根据唯一分解定理: a和b都可被分解为素因子的乘积,形如: 则显而易见的有一下结论: 相乘,得: 得证 几种求gcd的算法 欧几里得算法(辗转相除法) 辗转相减法(优化:stein_gcd) 欧几里得算法 基于事实: 实现: int gcd(int a, int b){ ) ? a : gcd( b , a % b) ; } 简短而…
GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2982    Accepted Submission(s): 1305 Problem Description Given two positive integers G and L, could you tell me how many solutions of…
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD. \[ x=(p_1^{i_1})*(p_2^{i_2})*(p_3^{i_3})\dots \] \[ y=(p_1^{j_1})*(p_2^{j_2})*(p_3^{j_3})\dots \] \[ z=(p_1^{k_1})*(p_2^{k_2})*(p_3^{k_3})\dots \] \…
题解:其实就是求n个数的lcm,由于数据特别大,求lcm时只能用质因子分解的方法来求. 质因子分解求lcm.对n个数每个数都进行质因子分解,然后用一个数组记录某个质因子出现的最大次数.然后累乘pow(x,cnt),即质因子x出现了cnt次. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; ll arr[N]; ll mp[N]; ll ksm(ll a,ll b){ ll res=; while(b)…
GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 3379    Accepted Submission(s): 1482 Problem Description Given two positive integers G and L, could you tell me how many solutions of…
题目链接:http://poj.org/problem?id=1845 定义: 满足a*k≡1 (mod p)的k值就是a关于p的乘法逆元. 为什么要有乘法逆元呢? 当我们要求(a/b) mod p的值,且a很大,无法直接求得a/b的值时,我们就要用到乘法逆元. 我们可以通过求b关于p的乘法逆元k,将a乘上k再模p, 即(a*k) mod p.其结果与(a/b) mod p等价.  题目解析:让求a^b的因子和modk,因为是大数没法直接求,因为求因子和函数是乘性函数,所以首先要质因子分解,化成…
题目链接: https://cn.vjudge.net/problem/POJ-2429 题目大意: 给出两个数的gcd和lcm,求原来的这两个数(限定两数之和最小). 解题思路: 首先,知道gcd和lcm求原来的两个数,需要分解lcm / gcd .将其分解为互质的两个数. 首先将lcm/gcd质因数分解,要分解出沪互质两个数字,那么这两个数字的gcd=1,也就是没有公共的质因子,所以可以直接枚举这两个数字的质因子,如果一个数要取这个质因子,就把它的指数全部取掉. 质因数分解用大数因式分解来做…
WUSTOJ 1266: gcd和lcm 参考 1naive1的博客 Description   已知a,b的最大公约数为x,也即gcd(a,b)=x; a,b的最小公倍数为y,也即lcm(a,b)=y.给出x,y.求满足要求的a和b一共有多少种. Input   多组测试样例.每组给两个整数x,y.(1<=x<=100000,1<=y<=1000000000). Output   对于每个测试样例,输出一个整数,表示满足要求的(a,b)的种数. Sample Input 3 60…
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and lcm(x, y, z) = L? Note, gcd(x, y, z) means the greatest common divisor of x, y and z, while lcm(x, y, z) means the…
组合数学 GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 451    Accepted Submission(s): 216 Problem Description Given two positive integers G and L, could you tell me how many solutions…
GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4497 Description Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and…
1485: [HNOI2009]有趣的数列 Description 我们称一个长度为2n的数列是有趣的,当且仅当该数列满足以下三个条件: (1)它是从1到2n共2n个整数的一个排列{ai}: (2)所有的奇数项满足a1<a3<…<a2n-1,所有的偶数项满足a2<a4<…<a2n: (3)任意相邻的两项a2i-1与a2i(1≤i≤n)满足奇数项小于偶数项,即:a2i-1<a2i. 现在的任务是:对于给定的n,请求出有多少个不同的长度为2n的有趣的数列.因为最后的答…
题目背景 这是一道签到题! 建议做题之前仔细阅读数据范围! 题目描述 我们定义一个函数:qiandao(x)为小于等于x的数中与x不互质的数的个数. 这题作为签到题,给出l和r,要求求. 输入输出格式 输入格式: 一行两个整数,l.r. 输出格式: 一行一个整数表示答案. 输入输出样例 输入样例#1: 233 2333 输出样例#1: 1056499 输入样例#2: 2333333333 2333666666 输出样例#2: 153096296 说明 对于30%的数据,. 对于60%的数据,.…
题目链接: https://cn.vjudge.net/problem/23709/origin 本题其实有坑 数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的 思路是最大公因数的倍数是最小公倍数,又有a <= b所以可以知道 a = gcd, b = lcm AC代码如下: #include <cstdio> #define ll long long using namespace std; int main() { int T; scanf("%d&quo…
GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9928   Accepted: 1843 Description Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the least common multiple (LCM) of a a…
P2043 质因子分解 题目描述 对N!进行质因子分解. 输入输出格式 输入格式: 输入数据仅有一行包含一个正整数N,N<=10000. 输出格式: 输出数据包含若干行,每行两个正整数p,a,中间用一个空格隔开.表示N!包含a个质因子p,要求按p的值从小到大输出. 因为\(N\)的范围比较小,我们考虑将范围内的质数打表打出来.因为一个数有唯一质数分解,分解为有限个质数的乘积,所以我们对每一个\(N\!\)的因子进行质数分解,将所有因数答案累计即可 附:线性筛 int prime[maxn], t…
GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 40    Accepted Submission(s): 22 Problem Description Given two positive integers G and L, could you tell me how many solutions of (x,…
P2043 质因子分解 对$n!$进行质因数分解的一种高效算法 首先,筛出$<=n$的素数 蓝后,对$n$反复除以$prime$,同时$cnt+=n/prime$ $n!$中含有该$prime$的个数即为$cnt$ #include<iostream> #include<cstdio> #include<cstring> #define re register using namespace std; #define N 10002 int n,v[N],pri[…
题意: 找出一个集合中的最大独立集,任意两数字之间不能是素数倍数的关系. 思路: 最大独立集,必然是二分图. 最大数字50w,考虑对每个数质因子分解,然后枚举所有除去一个质因子后的数是否存在,存在则建边,考虑到能这样建边的数一定是质因子个数奇偶不同,所以相当于按奇偶区分建立了二分图,然后求二分图最大匹配,得到最大独立集就行了. 有一点这个题数据比较大,直接匈牙利炸了,要Hopcroft-Karp优化才能过. #include <iostream> #include <cstring>…
题目描述 对N!进行质因子分解. 输入输出格式 输入格式: 输入数据仅有一行包含一个正整数N,N<=10000. 输出格式: 输出数据包含若干行,每行两个正整数p,a,中间用一个空格隔开.表示N!包含a个质因子p,要求按p的值从小到大输出. 输入输出样例 输入样例#1: 10 输出样例#1: 2 8 3 4 5 2 7 1 说明 10!=3628800=(2^8)*(3^4)*(5^2)*7  质因数分解.. #include<cstdio> ; int n; int cnt[maxn]…
题目链接:https://vjudge.net/problem/LightOJ-1138 1138 - Trailing Zeroes (III)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in…
题目链接:https://vjudge.net/problem/LightOJ-1336 1336 - Sigma Function    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ).…
GCD and LCM Descriptions: Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b. Input Input consists of several data sets. Each data set contains a and b separated by a single space in…
GCD _ LCM 是给你两个数A B 的最大公约数, 以及最小公倍数 the greatest common divisor and the least common multiply ! 最大公约数最简单.最常见的算法,就是辗转相除法   : 假设 GCD(A , B) ; A / B = P ;  A % B = Q;  那么 A =  B P + Q; GCD(B, Q); GCD (A , B)  % GCD (B , Q) = 0     :  因为 A  的表达式当中包括了 B .…