ural 1355. Bald Spot Revisited
2016-09-21 16:23
846 查看
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 b follow (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
题目大意:a每次乘一个x,求一个最长的次数,使a*x1*x2*x3*x4 。。。。= b
思路:如果b不能整除a, 输出0;
否则从从2 开始暴力算
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> #include <cstring> #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define RE(i, n) FOR(i, 1, n) #define FORP(i, a, b) for(int i = (a); i >= (b); i--) #define REP(i, n) for(int i = 0; i <(n); ++i) #define SZ(x) ((int)(x).size ) #define ALL(x) (x).begin(), (x.end()) #define MSET(a, x) memset(a, x, sizeof(a)) using namespace std; typedef long long int ll; typedef pair<int, int> P; int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } const double pi=3.14159265358979323846264338327950288L; const double eps=1e-6; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const int MAXN = 9000005; const int xi[] = {0, 0, 1, -1}; const int yi[] = {1, -1, 0, 0}; int prime[MAXN], cnt; bool a[MAXN]; int main() { //freopen("in.txt", "r", stdin); int t; scanf("%d", &t); while(t--) { int a, b, res = 0, k; scanf("%d%d", &a, &b); if(b%a == 0 && b >= a) { res++; k = b/a; for(int i = 2; i*i <=k && k > 1; i++) { while(k%i == 0) { // printf("%d ", i); k /= i; res++; } } if(k > 1) res++; } printf("%d\n", res); } return 0; }
相关文章推荐
- Ural 1355. Bald Spot Revisited 质因数分解
- ural 1355. Bald Spot Revisited(数的素因子划分)
- URAL 1355. Bald Spot Revisited(数论)
- ural 1355
- URAL 1355
- ural 1930 Ivan's Car(spfa)
- ural 1209. 1, 10, 100, 1000... 二分
- ural1108Heritage
- URAL1325-Dirt
- URAL 1277 浅谈无向图网络流约束建模方法
- ural 1057 Amount of degrees 【数位dp】
- 【poj2367】Genealogical tree 【Ural State University Internal Contest October'2000 Junior Session】
- 1355: [Baltic2009]Radio Transmission
- 51Nod-1355-斐波那契的最小公倍数
- URAL 1011|Conductors|暴力
- URAL 1083|Factorials!!!|暴力
- POJ 2601|URAL 1047|Simple Caluculations|数学推导
- ural 1101(Robot in the Field )表达式求值
- URAL 1036(数位dp)
- 《算法艺术与信息学竞赛》之 排序与检索 Ural1082-Gaby Ivanushka