hdu4497-GCD and LCM-(欧拉筛+唯一分解定理+组合数)
GCD and LCM
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 3409 Accepted Submission(s):
1503
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 least common multiple of x, y and z.
Note 2, (1, 2, 3) and (1, 3, 2) are two different solutions.
number of test cases.
The next T lines, each contains two positive 32-bit
signed integers, G and L.
It’s guaranteed that each answer will fit in a
32-bit signed integer.
solutions satisfying the conditions above.
6 72
7 33
0
y=p1b1*p2b2……psbs;
z=p1c1*p2c2……pscs;
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
#define ll long long
const int maxx=1e6+;
int prime[maxx];
int vis[maxx];
ll g,l;
int cnt;
void init()
{
memset(vis,true,sizeof(vis));
vis[]=vis[]=false;
cnt=;
for(int i=;i<=maxx;i++)
{
if(vis[i])
prime[cnt++]=i;
for(int j=;j<cnt && prime[j]*i<=maxx;j++)
{
vis[ i*prime[j] ]=false;
if(i%prime[j]==) break;
}
}
} int main()///hdu4497
{
init();
int t;
scanf("%d",&t);
while(t--)
{
ll ans=;
scanf("%lld%lld",&g,&l);
if(l%g)
printf("0\n");
else
{
for(int i=;i<cnt;i++)
{
int e=,h=;
while(g%prime[i]==)
{
e++;
g=g/prime[i];
}
while(l%prime[i]==)
{
h++;
l=l/prime[i];
}
if(h-e)
{
ans=ans*(h-e)*;
}
}
if(g==l)///32位范围内大素数因子只能有一个,l能被g整除证明这个大素数相同,不累乘
;
else if(l>)///如果g=1,l=大素数,再乘一次6
ans=ans*;
printf("%lld\n",ans);
}
}
return ;
}
hdu4497-GCD and LCM-(欧拉筛+唯一分解定理+组合数)的更多相关文章
- hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)
Deciphering Password Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 2018南京icpc-J-Prime Game (欧拉筛+唯一分解定理)
题意:给定n个数ai(n<=1e6,ai<=1e6),定义,并且fac(l,r)为mul(l,r)的不同质因数的个数,求 思路:可以先用欧拉筛求出1e6以内的所有质数,然后对所有ai判断, ...
- hdu3826-Squarefree number-(欧拉筛+唯一分解定理)
Squarefree number Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- noip复习——线性筛(欧拉筛)
整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...
- GCD nyoj 1007 (欧拉函数+欧几里得)
GCD nyoj 1007 (欧拉函数+欧几里得) GCD 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The greatest common divisor ...
- 欧拉筛,线性筛,洛谷P2158仪仗队
题目 首先我们先把题目分析一下. emmmm,这应该是一个找规律,应该可以打表,然后我们再分析一下图片,发现如果这个点可以被看到,那它的横坐标和纵坐标应该互质,而互质的条件就是它的横坐标和纵坐标的最大 ...
- 【BZOJ 2190】【SDOI 2008】仪仗队 欧拉筛
欧拉筛模板题 #include<cstdio> using namespace std; const int N=40003; int num=0,prime[N],phi[N]; boo ...
- [51NOD1181]质数中的质数(质数筛法)(欧拉筛)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1181 思路:欧拉筛出所有素数和一个数的判定,找到大于n的最小质 ...
- 素数筛&&欧拉筛
折腾了一晚上很水的数论,整个人都萌萌哒 主要看了欧拉筛和素数筛的O(n)的算法 这个比那个一长串英文名的算法的优势在于没有多次计算一个数,也就是说一个数只筛了一次,主要是在%==0之后跳出实现的,具体 ...
随机推荐
- Java - 20 Java 继承
Java 继承 继承是java面向对象编程技术的一块基石,因为它允许创建分等级层次的类.继承可以理解为一个对象从另一个对象获取属性的过程. 如果类A是类B的父类,而类B是类C的父类,我们也称C是A的子 ...
- angularjs的路由ui.router
<!-- 引入路由插件 --> <script src="vendor/angular-ui-router/release/angular-ui-router.min. ...
- shell中的时间值提取(date)
shell中的时间值提取(date) 方法1 # date +%F # date +%T # cat time.sh #!/bin/bash DATE=`date +%F | sed 's/-//g' ...
- express总结(一)
Express 框架核心特性: 可以设置中间件来响应 HTTP 请求. 定义了路由表用于执行不同的 HTTP 请求动作. 可以通过向模板传递参数来动态渲染 HTML 页面. express保留了Nod ...
- linux获取内存、cpu、负载、网口流量、磁盘信息
内存信息 / meminfo 返回dict #!/usr/bin/env python def memory_stat(): mem = {} f = open("/proc ...
- 转载:用Source Insight中看Python代码
在Source Insight中看Python代码 http://blog.csdn.net/lvming404/archive/2009/03/18/4000394.aspx SI是个很强大的代码查 ...
- 访问服务器时一直在转圈,等待localhost响应
之后把zookeeper的服务器的防火墙关了,就有响应了.可能就是防火墙的问题.
- Linux 配置开机自启 和 修改环境变量
[ 操作系统 Centos7 ] 一,开机自动启动的配置 1,赋予 /etc/rc.local 的执行权限 => chmod +x /etc/rc.local 2,在 /etc/rc.local ...
- Promise笔记
参考:阮一峰es6(http://es6.ruanyifeng.com/#docs/promise) 时间:2018-07-03 类型:个人笔记 解决的问题:异步编程的一种解决方案. 定义:Promi ...
- Oracle掌管权限和角色
转自:https://blog.csdn.net/without_bont/article/details/79862112 掌管权限和角色 这一部分我们主要看oracle中如何管理权限和角色,权限和 ...