题意:

思路:From https://blog.csdn.net/qq_36553623/article/details/76683438

大概就是把1e6里面的质因子能除的都除光之后借助两者gcd中有最大质因子的条件分类讨论

其实也就5类,重点是如何设分类的标准,其实唯一的标准就是对答案的贡献

int128本机环境跑不了,只能交上去的时候改,总觉得有朝一日要掉坑里

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N 1000000+10
#define M 200000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p) const int MOD=,inv2=(MOD+)/;
//int p=1e4+7;
double eps=1e-;
int dx[]={-,,,};
int dy[]={,,-,}; int p[N],b[N]; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} ll readll()
{
ll v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} template<class T> void Read(T &x)
{
static int CH;
while((CH=getchar())<''||CH>'');
for(x=CH-'';(CH=getchar())>=''&&CH<='';x=(x<<)+(x<<)+(CH-''));
} int is2(__int128 x)
{
__int128 t=pow(x,1.0/)+0.5;
if(t*t==x) return ;
return ;
} int is3(__int128 x)
{
__int128 t=pow(x,1.0/)+0.5;
if(t*t*t==x) return ;
return ;
} void calc(ll &ans,__int128 x,__int128 y)
{
if(y==)
{
if(x==) ans*=;
else if(is3(x)) ans*=;
else if(is2(x)) ans*=;
else ans*=;
}
else if(y>&&is2(y))
{
if(y%x==) ans*=;
else ans*=;
}
else if(x>&&is2(x))
{
if(x%y==) ans*=;
else ans*=;
}
else if(y%x==) ans*=;
else ans*=;
} int main()
{
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
int n=;
rep(i,,1e6)
{
if(!b[i]) p[++n]=i;
rep(j,,n)
{
int t=p[j]*i;
if(t>1e6) break;
b[t]=;
if(i%p[j]==) break;
}
}
int cas=read();
while(cas--)
{
__int128 s1,s2;
Read(s1);
Read(s2);
ll ans1,ans2;
ans1=ans2=;
rep(i,,n)
{
if(s1%p[i]==)
{
int s=;
while(s1%p[i]==)
{
s++;
s1/=p[i];
}
ans1*=s;
}
if(s2%p[i]==)
{
int s=;
while(s2%p[i]==)
{
s++;
s2/=p[i];
}
ans2*=s;
}
}
__int128 k=std::__gcd(s1,s2);
calc(ans1,k,s1/k);
calc(ans2,k,s2/k);
printf("%I64d %I64d\n",ans1,ans2);
}
return ;
}

【HDOJ5447】Good Numbers(数论)的更多相关文章

  1. UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

      Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people e ...

  2. UVA 10539 - Almost Prime Numbers(数论)

    UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...

  3. codeforces 446C DZY Loves Fibonacci Numbers 数论+线段树成段更新

    DZY Loves Fibonacci Numbers Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d &a ...

  4. POJ 3641 Pseudoprime numbers (数论+快速幂)

    题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...

  5. UVA138 Street Numbers(数论)

    题目链接. 题意: 找一个n,和一个m(m < n),求使得1~m的和等于m~n的和,找出10组m,n 分析: 列出来式子就是 m*(m+1)/2 = (n-m+1)*(m+n)/2 化简后为 ...

  6. Codeforces899C Dividing the numbers(数论)

    http://codeforces.com/problemset/problem/899/C tot为奇数时,绝对差为1:tot为偶数时,绝对差为0. 难点在于如何输出. #include<io ...

  7. hdu多校第八场 1003 (hdu6659) Acesrc and Good Numbers 数论/打表

    题意: 对于某数k,若数字d在1-k中出现次数恰好为k,则称k为好数. 给定d,x,求x以内,对于d而言最大的好数.k范围1e18. 题解: 打表二分即可. 但是,1e18的表是没法打出来的,只能在o ...

  8. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  9. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. C++学习 之 控制程序流程 (笔记)

    1.使用if...else有条件的执行 在一些时候语句需要进行有条件的执行.比如如果输入"Y"就执行赋值语句N=1:否则N=0: #include<iostream> ...

  2. codeforces 842C Ilya And The Tree (01背包+dfs)

    (点击此处查看原题) 题目分析 题意:在一个树中,有n个结点,记为 1~n ,其中根结点编号为1,每个结点都有一个值val[i],问从根结点到各个结点的路径中所有结点的值的gcd(最大公约数)最大是多 ...

  3. Windows系统下同时安装Python2和Python3

    Windows系统下同时安装Python2和Python3 说明 有时由于工作需求我们需要在Python2版本下面进行一些开发,有时又需要Python3以上的版本,那么我们怎么在一台电脑上同时安装多个 ...

  4. 牛客 545C 出题人的数组 (贪心)

    出题人有两个数组A,B,请你把两个数组归并起来使得$cost=\sum i c_i$最小. 归并要求原数组的数的顺序在新数组中不改变. 贪心水题 对于一段序列$A_i,A_{i+1},...,A_r$ ...

  5. redis 学习(11)-- redis pipeline

    redis pipeline 什么是流水线(pipeline) 首先来看 redis 执行一次操作所需要的时间: 1 次时间 = 1 次网络时间 + 1次命令时间 执行 n 次就需要: n 次时间 = ...

  6. java中接口知识点大总结

    接口的确很不好理解!!!!!那我来好好总结一下: 首先要理解接口是一个独立存在的,和类是不一样的东西,所以,直接用接口的定义是: 访问权限控制符 interface 接口名 [extends  接口列 ...

  7. Keepalived+Nginx+Tomcat 实现高可用Web集群

    https://www.jianshu.com/p/bc34f9101c5e Keepalived+Nginx+Tomcat 实现高可用Web集群 0.3912018.01.08 20:28:59字数 ...

  8. jQuery选择器引入

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  9. java实现生产者和消费者问题

    Java实现生产者和消费者问题 欢迎访问我的个人博客,获取更多有用的东西 链接一 链接二 也可以关注我的微信订阅号:CN丶Moti

  10. 【LeetCode】451-根据字符出现频率排序

    题目描述 给定一个字符串,请将字符串里的字符按照出现的频率降序排列. 示例 1: 输入: "tree" 输出: "eert" 解释: 'e'出现两次,'r'和' ...