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的更多相关文章

  1. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. viewport 详解

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale= ...

  2. Linux 各文件夹介绍

    http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命 ...

  3. WINDOWS Composer & PHPUnit 安装记录

    Windows: 安装Composer: 下载了composer_setup.exe 运行之后提示和Xdebug冲突,在php.ini中注释掉php_xdebug.dll,再次运行.通过 compos ...

  4. linux 之SCP

    一.从本地到远程复制 1.复制文件 * 命令格式: 1.scp -P remote_port local_file remote_username@remote_ip:remote_folder 或者 ...

  5. 深入SpringBoot:自定义PropertySourceLoader

    http://www.jianshu.com/p/5206f74a4406 ********************************* 前言 上一篇文章介绍了SpringBoot的Enable ...

  6. Design pattern---观察者模式

    观察者模式:发布/订阅模式,当某对象(被观察者)状态发生改变时所有订阅该对象的观察者对象(观察者)都将更新自己 成员(4种): 1.抽象被观察者:将所有的观察者对象的引用存入一个集合,并且定义了添加 ...

  7. SaltStack实战

    SaltStack实战 #安装 安装注意几点 python-libs-2.6.6-64.el6.x86_64 conflicts with file from package python-2.6.6 ...

  8. SG函数 专题练习

    [hdu1536][poj2960]S-Nim 题意 题意就是给出一个数组h,为每次可以取石子的数目. 然后给你n堆石子每堆si.求解先手能不能赢? 分析 根据\(h\)数组预处理出\(sg[i]\) ...

  9. html知识——表单

    1.表单标记:<form>内容</form> 属性:     name(表单名称) 必须写!!!  method(传送数据方式): get--将表单的内容附加在URL地址的后面 ...

  10. tab选项卡(选择上面的菜单,下面出现对应的不同的内容)

    使用jQuery完成 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...