博客
关于我
HDU - 4497 GCD and LCM 数论gcd
阅读量:269 次
发布时间:2019-03-01

本文共 2318 字,大约阅读时间需要 7 分钟。

文章目录

题意:

给三个数的 l c m lcm lcm g c d gcd gcd,求满足条件的三元组组合个数。

思路:

首先 l c m   m o d   g c d = = 0 lcm\bmod gcd==0 lcmmodgcd==0是有组合的条件,否则输出0。

现在可知 l c m ( x ′ , y ′ , z ′ ) = l c m ( x , y , z ) g c d ( x , y , z ) , g c d ( x ′ , y ′ , z ′ ) = 1 lcm(x^{'},y^{'},z^{'})=\frac{lcm(x,y,z)}{gcd(x,y,z)},gcd(x^{'},y^{'},z^{'})=1 lcm(x,y,z)=gcd(x,y,z)lcm(x,y,z)gcd(x,y,z)=1,对 a a a分解质因子得到 p 1 u 1 p 2 u 2 . . . p n u n p_1^{u_1}p_2^{u_2}...p_n^{u_n} p1u1p2u2...pnun,假设 x ′ = p 1 i 1 p 2 i 2 . . . p n j n , y ′ = p 1 j 1 p 2 j 2 . . . p n j n , z ′ = p 1 k 1 p 2 k 2 . . . p n k n x^{'}=p_1^{i_1}p_2^{i_2}...p_n^{j_n},y^{'}=p_1^{j_1}p_2^{j_2}...p_n^{j_n},z^{'}=p_1^{k_1}p_2^{k_2}...p_n^{k_n} x=p1i1p2i2...pnjn,y=p1j1p2j2...pnjn,z=p1k1p2k2...pnkn。那么由于 g c d ( x ′ , y ′ , z ′ ) = 1 gcd(x^{'},y^{'},z^{'})=1 gcd(x,y,z)=1,可知 m i n ( i 1 , j 1 , k 1 ) = 0 min(i_1,j_1,k_1)=0 min(i1,j1,k1)=0, m a x ( i 1 , j 1 , k 1 ) = u 1 max(i_1,j_1,k_1)=u_1 max(i1,j1,k1)=u1,所以我们需要找出来一个位置取 0 0 0,一个位置取 u 1 u_1 u1,其他的位置随意就好了。当前位置的答案即为 A 3 2 ∗ u 1 = 6 ∗ u 1 A_3^2*u_1=6*u_1 A32u1=6u1,那么 a n s = ∑ 6 ∗ u i ans=\sum6*u_i ans=6ui

//#pragma GCC optimize(2)#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define X first#define Y second#define L (u<<1)#define R (u<<1|1)#define pb push_back#define mk make_pair#define Mid (tr[u].l+tr[u].r>>1)#define Len(u) (tr[u].r-tr[u].l+1)#define random(a,b) ((a)+rand()%((b)-(a)+1))#define db puts("---")using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;typedef unsigned long long ULL;typedef pair
PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;const double eps=1e-6;LL g,l;int main(){ // ios::sync_with_stdio(false);// cin.tie(0); int _; scanf("%d",&_); while(_--) { scanf("%lld%lld",&g,&l); if(l%g!=0) { puts("0"); continue; } LL x=l/g; map
mp; for(int i=2;i<=x/i;i++) if(x%i==0) while(x%i==0) x/=i,mp[i]++; if(x>1) mp[x]++; LL ans=1; for(auto x:mp) ans*=6*x.Y; printf("%lld\n",ans); } return 0;}/**/

转载地址:http://hplx.baihongyu.com/

你可能感兴趣的文章
NISP国家信息安全水平考试,收藏这一篇就够了
查看>>
NIS服务器的配置过程
查看>>
NIS认证管理域中的用户
查看>>
Nitrux 3.8 发布!性能全面提升,带来非凡体验
查看>>
NiuShop开源商城系统 SQL注入漏洞复现
查看>>
NI笔试——大数加法
查看>>
NLog 自定义字段 写入 oracle
查看>>
NLog类库使用探索——详解配置
查看>>
NLP 基于kashgari和BERT实现中文命名实体识别(NER)
查看>>
NLP 模型中的偏差和公平性检测
查看>>
Vue3.0 性能提升主要是通过哪几方面体现的?
查看>>
NLP 项目:维基百科文章爬虫和分类【01】 - 语料库阅读器
查看>>
NLP_什么是统计语言模型_条件概率的链式法则_n元统计语言模型_马尔科夫链_数据稀疏(出现了词库中没有的词)_统计语言模型的平滑策略---人工智能工作笔记0035
查看>>
NLP三大特征抽取器:CNN、RNN与Transformer全面解析
查看>>
NLP学习笔记:使用 Python 进行NLTK
查看>>
NLP度量指标BELU真的完美么?
查看>>
NLP的不同研究领域和最新发展的概述
查看>>
NLP的神经网络训练的新模式
查看>>
NLP采用Bert进行简单文本情感分类
查看>>
NLP问答系统:使用 Deepset SQUAD 和 SQuAD v2 度量评估
查看>>