您的位置:首页 > 其它

ural 1355. Bald Spot Revisited

2016-09-21 16:23 846 查看

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 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

inputoutput
5
30 89
2 16
3 243
1 1
2 2

0
4
5
1
1

Problem Author: Aleksandr Bikbaev
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: