hdu4497 正整数唯一分解定理应用
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
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.
Output
Sample Input
6 72
7 33
Sample Output
0
由分步乘法计数原理,最终答案为(6*b1)*(6*b2)*........(6*bn)
#include <iostream>
#include <cstdio>
#include <cstring>
#include<algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn=2e5;//
bool vis[maxn];
ll prime[maxn/];
int tot;
void getprime()//因为n的范围是1e14,打表只需要打到sqrt(n)即可,最多只可能有一个素因子大于sqrt(n),最后特判一下即可;
{
memset(vis,true,sizeof(vis));
tot=;
for(ll i=;i<maxn;i++)
{
if(vis[i])
{
prime[tot++]=i;
for(ll j=i*i;j<maxn;j+=i)
{
vis[j]=false;
}
}
}
}
/*void Eulerprime()
{
memset(vis,true,sizeof(vis));
int tot=0;
for(int i=2;i<maxn;i++)
{
if(vis[i]) prime[tot++]=i;
for(int j=0;j<tot&&prime[j]*i<maxn;j++)
{
vis[i*prime[j]]=false;
if(i%prime[j]==0) break;
}
}
}*/
int a[],b[];
int cnt=;
void sbreak(ll n)//正整数唯一分解
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
cnt=;
for(int i=;prime[i]*prime[i]<=n;i++)
{
if(n%prime[i]==)
{
a[cnt]=prime[i];
while(n%prime[i]==)
{
b[cnt]++;
n/=prime[i];
}
cnt++;
}
}
if(n!=)
{
a[cnt]=n;
b[cnt]=;
cnt++;//为了使两种情况分解后素因子下标都是0~cnt-1;
}
}
int pow_mod(int m,int n)
{
ll pw=;
while(n)
{
if(n&) pw*=m;
m*=m;
n/=;
}
return pw;
}
int kase;
int main()
{
int T;
ll L,G;
getprime();
scanf("%d",&T);
kase=;
while(T--)
{
scanf("%lld%lld",&G,&L);
if(L%G) {printf("0\n");continue;}
ll n=L/G;
sbreak(n);
ll sum=;
for(int i=;i<cnt;i++)
{
sum*=(*b[i]);
}
printf("%lld\n",sum);
}
}
hdu4497 正整数唯一分解定理应用的更多相关文章
- hdu1215 正整数唯一分解定理应用
B - (例题)因子和 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64 ...
- lightoj 1236 正整数唯一分解定理
A - (例题)整数分解 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB 6 ...
- NOIP2009Hankson 的趣味题[唯一分解定理|暴力]
题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现 在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上,老师讲 ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
- UVa 10791 Minimum Sum LCM【唯一分解定理】
题意:给出n,求至少两个正整数,使得它们的最小公倍数为n,且这些整数的和最小 看的紫书--- 用唯一分解定理,n=(a1)^p1*(a2)^p2---*(ak)^pk,当每一个(ak)^pk作为一个单 ...
- 简单数论之整除&质因数分解&唯一分解定理
[整除] 若a被b整除,即a是b的倍数,那么记作b|a("|"是整除符号),读作"b整除a"或"a能被b整除".b叫做a的约数(或因数),a ...
- 唯一分解定理(以Minimun Sum LCM UVa 10791为例)
唯一分解定理是指任何正整数都可以分解为一些素数的幂之积,即任意正整数n=a1^p1*a2^p2*...*ai^pi:其中ai为任意素数,pi为任意整数. 题意是输入整数n,求至少2个整数,使得它们的最 ...
- hdu4497-GCD and LCM-(欧拉筛+唯一分解定理+组合数)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- hdu1215-七夕节-(埃氏筛+唯一分解定理)
七夕节 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- C/C++中new关键字是否加括号的区别
代码: #include <iostream> using namespace std; class A{ public: int a; }; int main(){ A *a1 = ne ...
- .attr()和.prop()和.css()的区别
是不是新手都会遇到这个问题?遇到过一次,在网上搜一搜,综合成了下面这样.重点参考了dolphin的‘jQuery的attr与prop’, 写的很清楚呢. 一般attribute翻译成中文术语为“特性” ...
- nRF51 DFU 初始化包介绍及生成工具
nRF51 DFU 初始化包 当升级数据包时,在应用程序映像传输之前,在DFU中需要初始化包来执行映像的安全检测.这个初始化包作为升级流程的一部分提供了安全检测机制,因此被升级的设备只能接收兼容的应用 ...
- centos6.6安装mysql5.7.6(采用MySQL Yum Repository)—(先看最后一行)
在centos6.6系统上采用MySQL Yum Repository安装mysql5.7.6: 帮助文档:http://dev.mysql.com/doc/refman/5.7/en/linux-i ...
- 这样就算会了PHP么?-6
关于PHP与WEB表单交互的CASE,十多年前没拾起来啊. 下一步进入JS与PHP的交互... <form name="form1" method="post&qu ...
- 编译Qt 4.7.3的时候发生NMAKE : fatal error U1077: 'cd' : return code '0x2'
怀疑是configure的时候没加-nomake demos -nomake examples的问题 references: http://stackoverflow.com/questions/10 ...
- fuck WPFG.org
今天一旦进入国外网站,就立刻跳转到WPFG.org.可能DNS被劫持污染了吧.用OpenDNS就行了.然后就没有这回事发生了 参考以下: https://www.opendns.com https:/ ...
- logstash tag使用说明
zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat stdin04.conf input { stdin { } } filter { # d ...
- Android Content Provider简介
Content Provider是Android的四大组件之一,与Activity和Service相同,使用之前需要注册: Android系统中存在大量的应用,当不同的应用程序之间需要共享数据时,可以 ...
- WebApi接口开发
文档 规范的文档对接口的开发有着至关重要的作用,规范的文档能够使 双方对接口的定义以及接口的参数都有一个明确的概念,便于沟通和联调. 在接口的开发过程中,为了保证传递参数的传递的私密性,参数传输是需要 ...