1355. Bald Spot Revisited

Time limit: 1.0 second
Memory limit: 64 MB
A student dreamt that he walked along the town where there were lots of pubs. He drank a mug of ale in each pub. All the pubs were numbered with positive integers and one could pass from the pub number n to the pub with a number that divides n. The dream started in the pub number a. The student knew that he needed to get to the pub number b. It’s understood that he wanted to drink on the way as much ale as possible. If he couldn’t get from the pub number a to the pub number b he woke up immediately in a cold sweat.

Input

The first line contains an integer T — an amount of tests. Then T lines with integers a and bfollow (0 ≤ T ≤ 20; 1 ≤ ab ≤ 109).

Output

For each test in a separate line you are to output the maximal number of mugs that the student could drink on his way.

Sample

input output
5
30 89
2 16
3 243
1 1
2 2
0
4
5
1
1

题意:一个学生梦到自己在一条有很多酒吧的街上散步。他可以在每个酒吧喝一杯酒。所有的酒吧有一个正整数编号,这个人可以从n号酒吧走到编号能整除n的酒吧。现在他要从a号酒吧走到b号,请问最多能喝到多少酒。题目中保证所有数据均为质数之积。

思路:

直接暴力就可以;

第一:如果由a可以到达b,那么a一定可以整除b;

第二:将b除以a后的结果进行素数划分就可以,计算划分出了多少个数就可以计算出最多所喝酒的次数

 #include<iostream>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
long long a,b;
int sum(long long n)
{
int sumnumber=;
while(){
int i;
for(i=;i*i<=n;i++){
if(n%i==){
while(n%i==){
sumnumber++;
n/=i;
break;
}
break;
}
}
if(i*i>n){
if(n>){
sumnumber++;
}
break;
}
}
return sumnumber;
} int main()
{
// freopen("input.txt","r",stdin);
int n;
scanf("%d",&n);
while(n--){
cin>>a>>b;
if(b%a!=){//b不可以被a整除,表明无论如何由a都不可能到达b的
printf("0\n");
continue;
}
if(b==a){//a等于b那么不用动就可以的
printf("1\n");
continue;
}
if(a>b){//a大于b这样一定不可以由a到达b的
printf("0\n");
continue;
}
int ans=+sum(b/a);//计算b除以a的素数划分
printf("%d\n",ans);
}
return ;
}

ural 1355. Bald Spot Revisited(数的素因子划分)的更多相关文章

  1. URAL 1355. Bald Spot Revisited(数论)

    题目链接 题意 : 一个学生梦到自己在一条有很多酒吧的街上散步.他可以在每个酒吧喝一杯酒.所有的酒吧有一个正整数编号,这个人可以从n号酒吧走到编号能整除n的酒吧.现在他要从a号酒吧走到b号,请问最多能 ...

  2. URAL1355. Bald Spot Revisited

    1355 其实就是求质因子的个数 这样肯定是最多的 注意一下 除到最后不是1的情况 #include <iostream> #include<cstdio> #include& ...

  3. URAL 1934 Black Spot(最短路)

    Black Spot Time limit: 1.0 secondMemory limit: 64 MB Bootstrap: Jones's terrible leviathan will find ...

  4. URAL 1934 Black Spot --- 最短的简单修改

    右侧是1.维护的同时保持最短路p值至少,我有直接存款(1-p).该概率不满足,为了使这个值极大. #include <iostream> #include <cstdlib> ...

  5. 第k个素因子只有3 5 7 的数

    题目描述 有一些数的素因子只有3.5.7,请设计一个算法,找出其中的第k个数. 给定一个数int k,请返回第k个数.保证k小于等于100. 测试样例: 3 返回:7 int findKth(int ...

  6. Zoj 3529 A Game Between Alice and Bob 数论+博弈Nim 快速求数中有多少个素数因子

    本题涉及博弈论中的Nim游戏博弈. Nim游戏博弈详解链接: http://www.cnblogs.com/exponent/articles/2141477.html 本题解题报告详解链接: htt ...

  7. Stirling数笔记

    Updating.... 这几个玩意儿要记的东西太多太乱所以写blog整理一下 虽然蒯的成分会比较多全部 我居然开始记得写blog了?? 第一类 这里讨论的是无符号类型的. OEIS编号A130534 ...

  8. [MySQL] Innodb參数优化

    innodb_buffer_pool_size innodb_buffer_pool_size 參数用来设置Innodb 最基本的Buffer(Innodb_Buffer_Pool)的大小,也就是缓存 ...

  9. 二刷Cracking the Coding Interview(CC150第五版)

    第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...

随机推荐

  1. 第一百二十二节,JavaScript表单处理

    JavaScript表单处理 学习要点: 1.表单介绍 2.文本框脚本 3.选择框脚本 为了分担服务器处理表单的压力,JavaScript提供了一些解决方案,从而大大打破了处处依赖服务器的局面. 一. ...

  2. 在CentOS上安装第三方软件库EPEL

    Extra Packages for Enterprise Linux (EPEL)[企业版 Linux 附加软件包(以下简称 EPEL)]是一个由特别兴趣小组创建.维护并管理的,针对 红帽企业版 L ...

  3. 四步安装typecho(LNMP环境)

    ##1 安装nginx,mysql,php环境 sudo apt-get install nginx php5-fpm php5-cgi php5-cli php5-curl php5-gd php5 ...

  4. ionic中$ionicPopover和$ionicModal

    Popover可点多个按钮弹出同一个浮动框但内容不一样.那想要在同一页面弹出不同的浮动框怎么办呢? 这事就用到了$ionicModal,他和$ionicPopover一样的用法. 请看图: html: ...

  5. C# 从零开始 vol.2

    这是第二篇 1:命名空间 命名空间可以理解成类的文件夹,这个命名空间中存放着各种类,当你需要使用到对应的类的时候,就需要导入命名空间后才能使用. 引用:可以理解成添加新的存放类的文件夹,也就是一个项目 ...

  6. [Rails] 从 Request 到 Response(1)

    本文翻译自:Rails from Request to Response 系列:个人选择了自己感兴趣的部分进行翻译,需要阅读原文的同学请戳前面的链接. 第一部分 导言(Introduction) 服务 ...

  7. HTML表格标记

  8. Gym 101102C Bored Judge(set--结构体集合)

    这个故事告诉我们,WA了一定要找自己的原因... ... 当我开始用set去做的时候,发现一直过不去,一开始忘了把初始排名加进去,后来忘了第0秒,第0秒第一的id = 1 这个题目的做法也不只这一种, ...

  9. msyql sql语句

    参考: http://www.cnblogs.com/aspnethot/articles/1397130.html 修改表字段ALTER TABLE table_name CHANGE old_fi ...

  10. 分布式版本控制系统Git-----2.上传至远程仓库之基础版

    好,之前已经将文档下载下来了,但是我感觉还是将自己之前截的图放出来比较好,自己整理的,但是总不能放桌面上,时间久了也会忘得,索性放到博客上吧,也便于其他人查看,简直是百利而无一害啊.哈哈.来吧. 注意 ...