Ural 1355. Bald Spot Revisited 质因数分解
2013-07-31 20:56
357 查看
1355. Bald Spot Revisited
Time limit: 1.0 secondMemory 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
input | output |
---|---|
5 30 89 2 16 3 243 1 1 2 2 | 0 4 5 1 1 |
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 1355. Bald Spot Revisited(数论)
- ural 1355. Bald Spot Revisited(数的素因子划分)
- URAL 1355
- ural 1355
- Ural 1091. Tmutarakan Exams 排列组合+容斥原理+质因数分解
- URAL1517Freedom of Choice(后缀数组)
- Pollard's Rho 快速质因数分解 复习小记
- 51Nod 1355 斐波那契的最小公倍数
- T1098 质因数分解(#Ⅰ- 4 - 2)
- ural1297
- URAL - 1098 Questions——约瑟夫环
- bzoj 1355: [Baltic2009]Radio Transmission【kmp】
- ural==acm==题目分类
- ural 1156
- [URAL 1553]Caves and tunnels(树链剖分)
- Ural 1449 Credit Operations 2
- ural 1002 phone numbers
- ural 1033 Labyrinth
- ural 1416 Confidential