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
  1. 5
  2. 30 89
  3. 2 16
  4. 3 243
  5. 1 1
  6. 2 2
  1. 0
  2. 4
  3. 5
  4. 1
  5. 1

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

思路:

直接暴力就可以;

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

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

  1. #include<iostream>
  2. #include<cmath>
  3. #include<map>
  4. #include<cstdio>
  5. using namespace std;
  6. long long a,b;
  7. int sum(long long n)
  8. {
  9. int sumnumber=;
  10. while(){
  11. int i;
  12. for(i=;i*i<=n;i++){
  13. if(n%i==){
  14. while(n%i==){
  15. sumnumber++;
  16. n/=i;
  17. break;
  18. }
  19. break;
  20. }
  21. }
  22. if(i*i>n){
  23. if(n>){
  24. sumnumber++;
  25. }
  26. break;
  27. }
  28. }
  29. return sumnumber;
  30. }
  31.  
  32. int main()
  33. {
  34. // freopen("input.txt","r",stdin);
  35. int n;
  36. scanf("%d",&n);
  37. while(n--){
  38. cin>>a>>b;
  39. if(b%a!=){//b不可以被a整除,表明无论如何由a都不可能到达b的
  40. printf("0\n");
  41. continue;
  42. }
  43. if(b==a){//a等于b那么不用动就可以的
  44. printf("1\n");
  45. continue;
  46. }
  47. if(a>b){//a大于b这样一定不可以由a到达b的
  48. printf("0\n");
  49. continue;
  50. }
  51. int ans=+sum(b/a);//计算b除以a的素数划分
  52. printf("%d\n",ans);
  53. }
  54. return ;
  55. }

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. http&https&证书&数字签名

    http协议 http是超文本传输协议,是用来网络间传输数据.底层是tcp协议(传输控制协议). 是一种面向连接的主机对主机层的可靠传输,这里的可靠是指数据丢失极小.Tcp建立一次连接需要经过3次握手 ...

  2. Python学习笔记——基础篇【第六周】——PyYAML & configparser模块

    PyYAML模块 Python也可以很容易的处理ymal文档格式,只不过需要安装一个模块,参考文档:http://pyyaml.org/wiki/PyYAMLDocumentation 常用模块之Co ...

  3. C# 语言规范_版本5.0 (第6章 转换)

    1. 转换 转换(conversion) 使表达式可以被视为一种特定类型.转换可导致将给定类型的表达式视为具有不同的类型,或其可导致没有类型的表达式获得一种类型.转换可以是隐式的 (implicit) ...

  4. Python学习日志(一)

    1.os - Normal Method: os.name() : os.getcwd(): 给出当前的目录,python当前的工作目录 os.listdir(): 返回 os.remove():删除 ...

  5. linux 命令展示该目录下的所有子目录及文件结构 tree

    1. apt-get install tree 2. tree -d -L 1 解释: tree :显示目录树: -d : 只显示目录: -L 1 : 选择显示的目录深度为1 , 只显示一层深度. 目 ...

  6. C++实现中缀表达式转前、后缀

    #include<iostream> #include<string> #include<stack> using namespace std; bool isIn ...

  7. Express ( MiddleWare/中间件 路由 在 Express 中使用模板引擎 常用API

    A fast, un-opinionated, minimalist web framework for Node.js applications. In general, prefer simply ...

  8. 数据结构之线性表的顺序存储结构的实现--C语言版

    #include <stdio.h> #include <stdlib.h> #include <time.h> #define INIT_SIZE 100 #de ...

  9. [转] Android root 原理

    欢迎转载,转载请注明出处:http://www.cnblogs.com/lanrenxinxin/p/5572640.html 0x00 关于root linux和类Unix系统的最初设计都是针对多用 ...

  10. 32bit程序在64bit操作系统下处理重定向细节(转自http://bbs.pediy.com/showthread.php?t=89054)

    1. 64bit操作系统的重定向机制以及目的 在64bit操作系统中,为了无缝兼容32bit程序的运行,64bit的Windows操作系统采用重定向机制.目的是为了能让32bit程序在64bit的操作 ...