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 ...
随机推荐
- GnuPG 的PGP使用
1. 生成秘钥对(此处采用默认的RSA, 2048位) $ gpg --gen-key gpg (GnuPG) ; Copyright (C) Free Software Foundation, In ...
- Android动画View Animation
Animations 一.Animations介绍 Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转.缩放.淡入淡出等, ...
- 常用js总结1
1.cookie.js(封装了cookie的基本操作) 1.引入cookie.js <script type="text/javascript" src="../j ...
- iOS OAuth2.0认证和SSO授权
OAuth2.0和SSO授权 一.OAuth2.0授权协议 一种安全的登陆协议,用户提交的账户密码不提交到本APP,而是提交到授权服务器,待服务器确认后,返回本APP一个访问令牌,本APP即可用该 ...
- Count Primes - LeetCode
examination questions Description: Count the number of prime numbers less than a non-negative number ...
- js获取url中的参数值
在博客园看家一片不错的文章:http://www.cnblogs.com/EnderH/p/5398409.html 在这里记下对自己比较有用的三种: 1.正则 function GetQuerySt ...
- Linux Shell 批量更换文件名或后缀名
把下列所有.c的文件名修改为.cc rename .c .cc *.c
- iscroll 使用及遇到的问题
介绍: iscroll.js 是滑动事件.在手机上可以快速的滑动,用户体验很好.在线例子: 选择套餐 iScroll必须在调用之前实例化---用法 <script src="iscro ...
- timer控件、三级联动
timer控件: 实现时间日期自增长: using System; using System.Collections.Generic; using System.ComponentModel; usi ...
- 使用Nexus创建Maven私服
Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问.利用Nexus你可以只在一个地方就能够完全控制访问和部署在你所维护仓库中的每个Artifact.Nexus ...