HDU 3353
http://acm.hdu.edu.cn/showproblem.php?pid=3353
题目其实就是要把A B分解质因数,X是它们质因数的并集,D是质因数指数的和(如果有相同的质因数,把它们的指数做减法求绝对值)
水题,wa了好多次,手抖最后把while敲成if...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <set> using namespace std; int a[],ac[],b[],bc[]; int ABS(int x){
return x>?x:-x;
} int main(){
int A,B;
int cas=;
while(~scanf("%d%d",&A,&B)){
if(!A && !B)break;
int st1,st2;
st1=st2=;
memset(ac,,sizeof(ac));
memset(bc,,sizeof(bc));
for(int i=;i*i<=A;i++){
if(A%i==){
a[st1]=i;
while(A%i==){
ac[st1]++;
A/=i;
}
st1++;
}
}
if(A>){
a[st1]=A;
ac[st1++]=;
}
for(int i=;i*i<=B;i++){
if(B%i==){
b[st2]=i;
while(B%i==){
bc[st2]++;
B/=i;
}
st2++;
}
}
if(B>){
b[st2]=B;
bc[st2++]=;
}
int i,j;
i=j=;
int X,D;
X=D=;
while(i<st1 && j<st2){
if(a[i]==b[j]){
X++;
D+=ABS(ac[i]-bc[j]);
i++;j++;
}
else if(a[i]<b[j]){
X++;
D+=ac[i];
i++;
}
else{
X++;
D+=bc[j];
j++;
}
}
while(i==st1 && j<st2){
X++;
D+=bc[j];
j++;
}
while(j==st2 && i<st1){
X++;
D+=ac[i];
i++;
}
printf("%d. %d:%d\n",cas++,X,D);
}
return ;
}
HDU 3353的更多相关文章
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- [Machine-Learning] 熟悉 Numpy
Numpy 是 Python 中的一个模块,主要用于处理数学和计算相关的问题,这里是一个入门的介绍. 导入 习惯上可以这样导入: import numpy as np 在 machine learni ...
- python学习之字典
1.字典 列表存储的数据比较单一也不够灵活,这时我们可以使用字典来存储某些多内容的数据,字典是无顺序的 1.简单的字典 book={ 'huqiang':13457412571, 'Jasper':1 ...
- Mifare系列1-简介(转)
文章转自 文/闫鑫原创转载请注明出处http://blog.csdn.net/yxstars/article/details/38079827 感谢原创作者的辛勤,对您再次表达感谢! 随着社会的发展, ...
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- Gitblit Go
1.Download the "Gitblit Go" package from the www.gitblit.com 2.UnZip the package 3.Open th ...
- http://www.oreilly.com/catalog/errataunconfirmed.csp?isbn=9780596529321
集体智慧勘误表: http://www.oreilly.com/catalog/errataunconfirmed.csp?isbn=9780596529321 ------------------- ...
- 了解less跟sass
less官网:http://www.bootcss.com/p/lesscss/ LESS编写技巧分享:http://www.xuanfengge.com/less-writing-skills-sh ...
- oracle的存储过程和函数(PL/SQL)
czmmiao 存储过程概述 存储过程是子程序的一种类型,能够完成一些任务,作为schema对象存储于数据库.是一个有名字的PL/SQL代码块,支持接收或不接受参数,同时也支持参数输出.一个存储过程通 ...
- 小韦XPSP3 V10.0_Ghost精简版
小韦XPSP3 V10.0_Ghost精简版 该版本基于小韦XPSP3 V10.0,用EasySysprep_4.1进行重新封装,最大程度保持原版极度精简的理念.C盘为NTFS格式,安装后C盘只占用2 ...
- SPSS数据分析——t检验
SPSS中t检验全都集中在分析—比较均值菜单中.关于t检验再简单说一下,我们知道一个统计结果需要表达三部分内容,即集中性.变异性.显著性. 集中性的表现指标是均值变异的的表现指标是方差.标准差或标准误 ...