Hankson 的趣味题sol

Hankson 的趣味题

  • 简单推一下式子,发现(gcd(x/a1,a0/a1)=1,gcd(b1/b0,b1/x))
  • 直接枚举会超时
  • (x=k*a1)(k|(b1/a1)),枚举(b1/a1)的约数就可以了
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define U(i,u) for(register int i=head[u];i;i=nxt[i])
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define per(i,a,b) for(register int i=(a);i>=(b);--i)
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
using namespace std;
typedef double db;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 ill;
typedef unsigned int ui;
typedef pair<int,int> PII;
typedef vector<int> VI;
template<class T> inline void read(T &x){x=0;char c=getchar();int f=1; while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();}x*=f; }
template<class T> inline void print(T x) {if(x<0)putchar('-'),x =-x;if(x < 10)putchar(x + 48);else print(x/10),putchar(x%10+48);}
template<class T> inline void cmin(T &x, T y){x=x<y?x:y;}
template<class T> inline void cmax(T &x, T y){x=x>y?x:y;}
int n,a0,a1,b0,b1;
int gcd(int x,int y){
	if(y==0)return x;
	return gcd(y,x%y);
}
int main(){
	read(n);while(n--){
		read(a0);read(a1);read(b0);read(b1);int tmp=0;
		if(b1%a1!=0){printf("%d
",tmp);continue;}int dd=b1/a1;
		rep(i,1,sqrt(dd)){
			if(dd%i==0){
				if(gcd(i,a0/a1)==1&&gcd(b1/b0,dd/i)==1)++tmp;
				if(i*i!=dd){
					if(gcd((dd/i),a0/a1)==1&&gcd(b1/b0,i)==1)++tmp;
				}
			}
		}
		printf("%d
",tmp);
	}
	return 0;
}
原文地址:https://www.cnblogs.com/hangzz/p/13405451.html