洛谷 1072
来源:互联网 发布:淘宝开店类目如何选择 编辑:程序博客网 时间:2024/06/07 23:18
【题目分析】
唯一分解定理。
【代码】
#include <cstdio>#include <cmath>#include <cstring>#include <iostream>#include <algorithm>#define ll long long#define inf 0x3f3f3f3fusing namespace std;int tt;long long ans;int a0,a1,b0,b1;int p[100010],a[100010],now[100010],top=0;int aa[100010],anow[100010];inline long long gcd(long long a,long long b){return (b==0)?a:gcd(b,a%b);}inline void init(){ ans=1;top=0;}inline long long solve(){ scanf("%d%d%d%d",&a0,&a1,&b0,&b1); if (b0>b1) return 0; if (gcd(b1,b0)!=b0) return 0; long long x=b1; for (int i=2;(ll)i*i<x;++i) { if (b1%i==0) { p[++top]=i; a[top]=0; now[top]=0; while (b1%i==0) { a[top]++; b1/=i; } while (b0%i==0) { now[top]++; b0/=i; } } } if(b1>1) { p[++top]=b1; a[top]=1; now[top]=0; while (b0%b1==0) now[top]++,b0/=b1; } for (int i=1;i<=top;++i) { aa[i]=0; anow[i]=0; while (a1%p[i]==0) { a1/=p[i]; aa[i]++; } while (a0%p[i]==0) { a0/=p[i]; anow[i]++; } } for (int i=1;i<=top;++i) { int l1,r1; if (now[i]>a[i]) l1=inf,r1=-inf; else if (a[i]>now[i]) l1=a[i],r1=a[i]; else l1=0,r1=a[i]; int l2,r2; if (aa[i]<anow[i]) l2=aa[i],r2=aa[i]; else if (aa[i]==anow[i]) l2=aa[i],r2=inf; else r2=-inf,l2=inf; int tmp=0; int l,r; if (l2>l1) l=l2; else l=l1; if (r2>r1) r=r1; else r=r2; if (r-l+1<=0) return 0; else ans*=(r-l+1); } return ans;}int main(){ scanf("%d",&tt); while (tt--) { init(); printf("%lld\n",solve()); }}
0 0
- 洛谷 1072
- 洛谷 1072
- 【NOIP2009】洛谷1072 Hankson的趣味题
- 洛谷1072 Hankson 的趣味题
- 1072
- 洛谷1072 hankson的趣味题 数论乱搞 非标准解法
- xoj 1072
- HDF 1072
- hdu 1072
- POJ 1072
- hdu 1072
- hdu 1072
- Nightmare 1072
- sdjzu 1072
- hdu 1072
- pat 1072
- 1072:迷宫
- hdu 1072
- 关于中文乱码问题的解决
- 浅析Python的GIL和线程安全
- iOS10 在4G下调用QQ SDK崩溃(WiFi下没事)
- 浅析Java中CountDownLatch用法
- WeUI
- 洛谷 1072
- 奥运奖牌中文系统(IO版)
- DOM事件学习笔记
- 适配器模式
- Android通过Get方法获取Json数据
- java NIO Buffer常用方法
- AJAX学习笔记
- JUC (Java Util Concurrency) 基础内容概述
- HDU - 2516 取石子游戏(斐波那契)