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. HDU 5873 Football Games

    随便判了几个条件就过了,也不知道对不对的. 正解应该是: $[1].$${s_1} + {s_2} + {s_3} + ...... + {s_n} = n(n - 1)$ $[2].$${s_1} ...

  2. USACO 3.2 Factorials

    Factorials The factorial of an integer N, written N!, is the product of all the integers from 1 thro ...

  3. asp.net 如何引用dll

    这要看你引用dll文件是什么文件,是单纯的类库还是外部或自定义控件dll文件. 如果是类库dll文件,引用的步骤是这样的:在解决方案管理器中,选中要添加引用的项目或网站-右击-添加引用-选择要添加的d ...

  4. PAT乙级1004. 成绩排名 (20)

    读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 学号 成绩 第3行:第2个学生 ...

  5. hdu 3480 Division(斜率优化DP)

    题目链接:hdu 3480 Division 题意: 给你一个有n个数的集合S,现在让你选出m个子集合,使这m个子集合并起来为S,并且每个集合的(max-min)2 之和要最小. 题解: 运用贪心的思 ...

  6. C#变量修饰符

    访问修饰符 关键字包括:internal,public,protected和private,用于设置变量的访问级别.  public  变量可以做为它所属的类型的一个字段,可以在任何地方访问它.  i ...

  7. Android:dialog去除边框的实现(自带Style的padding)

    public void show(View view) { MyDialog myDialog=new MyDialog(MainActivity.this); myDialog.show(); // ...

  8. 【原创】Spring MVC项目搭建(使用Java配置)

    一.使用Intellij idea,新建maven项目,选择maven-archetype-webapp. 二.在src/main下新建文件夹,命名为java,并标注为source folder. 三 ...

  9. Python3与Python2的区别汇总

    1.print 在Python3.0  是一个函数,正确输入应该是:print (3x) 2.raw_input 在Python3.0改成input

  10. jqGrid使用整理

    jqGrid使用整理 jqGrid是一款处理表格展现的jQuery插件,支持分页.滚动加载.搜索.锁定.拖动等一系列对表格的常规操作.以下是最近项目中实践jqGrid的整理 1.引入到项目中来 jqG ...