Ural 1355. Bald Spot Revisited 质因数分解
来源:互联网 发布:网络广告公司经营项目 编辑:程序博客网 时间:2024/05/20 06:27
1355. Bald Spot Revisited
Time limit: 1.0 second
Memory limit: 64 MB
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 ≤ a, b ≤ 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
530 892 163 2431 12 2
04511
Problem Author: Aleksandr Bikbaev
Problem Source: USU Junior Championship March'2005
Problem Source: USU Junior Championship March'2005
题目中保证所有数据均为质数之积,这样就不用再素数测试了,直接暴力就行了。
#include <iostream>#include <cstdio>using namespace std;int beer(int t){ int i; for(i = 2; i*i <= t; i ++) { if(t%i == 0) return 1+beer(t/i); } return 0;}int main(){ int a, b, ncase, ans; scanf("%d", &ncase); while(ncase --) { scanf("%d%d", &a, &b); if(a > b) { printf("0\n"); continue; } if(a == b) { printf("1\n"); continue; } ans = 0; if(b%a == 0) ans = 2+beer(b/a); printf("%d\n", ans); } return 0;}
- Ural 1355. Bald Spot Revisited 质因数分解
- Ural 1091. Tmutarakan Exams 排列组合+容斥原理+质因数分解
- URAL - 2102 Michael and Cryptography 分解质因数+优化
- 分解质因数
- 分解质因数
- 质因数分解
- 分解质因数
- 质因数分解
- 分解质因数
- 分解质因数
- 质因数分解
- 分解质因数
- 分解质因数
- 分解质因数
- 分解质因数
- 分解质因数
- 分解质因数
- 分解质因数
- Java学习之道:mybatis简单应用(基于配置文件)
- 2013多校联合训练第三场
- Android PULL解析XML
- 【算法题】:跳台阶问题及斐波那契Fibonacci序列
- struts2自定义类型转换小插曲
- Ural 1355. Bald Spot Revisited 质因数分解
- 索引覆盖分析
- js中new Function的用法
- Android 内存数据库
- PAT_1055: The World's Richest
- 15-数据结构_递归
- TextBox中限制全角输入
- SQL SERVER 本地查询更新操作远程数据库
- 非主流家族繁体字网名:/╱●銘秂娯樂、