记录编号 190615 评测结果 AAAAAAAAAA
题目名称 [NOIP 2009]Hankson的趣味题 最终得分 100
用户昵称 Gravatar啊吧啦吧啦吧 是否通过 通过
代码语言 C++ 运行时间 0.038 s
提交时间 2015-10-03 21:14:19 内存使用 0.58 MiB
显示代码纯文本
#include <iostream>
#include <fstream>

using namespace std;

int n,a0,a1,b0,b1,tmp=0,prime[55001],low,high,sum,aa0,aa1,bb0,bb1;
bool l[55001];	//false->prime
ifstream fin("son.in");
ofstream fout("son.out");
#define cin fin
#define cout fout
inline void gao(int);
inline int esum(int&, int);

main()
{
	for (int i = 2; i < 55000; ++i)
		if (! l[i]){
			prime[tmp++] = i;
			if (i <= 223) 
				for (int j = i * i; j <= 55000; j += i)
					l[j] = true;
		}
	cin >> n;
	while (n--){
		cin >> a0 >> a1 >> b0 >> b1;
		sum = 1;
		high = low = 0;
		for (int i = 0; prime[i] * prime[i] <= b1 && prime[i]; ++i)
			gao(prime[i]);
		if (b1 > 1)
			gao(b1);
		cout << sum << endl;
	}
	
	fin.close();
	fout.close();
//	for (; ; );
}

inline void gao(int x){
	aa0 = esum(a0, x);
	aa1 = esum(a1, x);
	bb0 = esum(b0, x);
	bb1 = esum(b1, x);
	low = aa1;
	if (bb0 < bb1)
		low = bb1;
	high = bb1;
	if (aa0 > aa1)
		high = aa1;
	if (high >= low)
		sum *= (high - low + 1);
	else
		sum = 0;
}

inline int esum(int& a, int x){
	int s = 0;
	while (! (a % x)){
		a /= x;
		++s;
	}
	return s;
}