【HDOJ5447】Good Numbers(数论)
题意:

思路: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(数论)的更多相关文章
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ...
- UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...
- codeforces 446C DZY Loves Fibonacci Numbers 数论+线段树成段更新
DZY Loves Fibonacci Numbers Time Limit:4000MS Memory Limit:262144KB 64bit IO Format:%I64d &a ...
- POJ 3641 Pseudoprime numbers (数论+快速幂)
题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...
- UVA138 Street Numbers(数论)
题目链接. 题意: 找一个n,和一个m(m < n),求使得1~m的和等于m~n的和,找出10组m,n 分析: 列出来式子就是 m*(m+1)/2 = (n-m+1)*(m+n)/2 化简后为 ...
- Codeforces899C Dividing the numbers(数论)
http://codeforces.com/problemset/problem/899/C tot为奇数时,绝对差为1:tot为偶数时,绝对差为0. 难点在于如何输出. #include<io ...
- hdu多校第八场 1003 (hdu6659) Acesrc and Good Numbers 数论/打表
题意: 对于某数k,若数字d在1-k中出现次数恰好为k,则称k为好数. 给定d,x,求x以内,对于d而言最大的好数.k范围1e18. 题解: 打表二分即可. 但是,1e18的表是没法打出来的,只能在o ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- javase-整数变量的交换
public class Operator { public static void main(String[] args) { int a=10; int b=20; System.out.prin ...
- 解决PowerDesigner提示This data item is already used in a primary identifier
解决PowerDesigner提示This data item is already used in a primary identifier 解决PowerDesigner提示This data i ...
- Coins —— POJ-1742
Time limit 3000 ms Memory limit 30000 kB Description People in Silverland use coins.They have coins ...
- vscode中eslint插件的配置-prettier
用vue-cli构建vue项目,会有个eslint代码检测的安装 可vscode自带代码格式化是prettier格式(右键有格式化文件或alt+shift+f) 这时候要在vscode上装一个esli ...
- 最好用linux版QQ
这个版本的qq是见过linux下做好用的qq,希望对大家有用; 安装简单,qq易用,不卡死,可以接收文件. 安装过程如下: git clone https://gitee.com/wszqkzqk/d ...
- node工具之http-proxy-middleware
简介 一个轻松的配置代理服务器的中间件,让Node.js代理变得简单 url路径 foo://example.com:8042/over/there?name=ferret#nose \_/ \___ ...
- Windows7/win10系统安装JDK的环境变量设置javac不是内部命令或外部命令
---恢复内容开始--- Windows7/win10系统安装JDK的环境变量设置 Windows7 X64安装“jdk-6u26-windows-x64.exe”后,按照网上的环境变量设置方法设置了 ...
- input在获得焦点时外边框不变色
input:focus{ ouline:none; }
- c++ 初学者的画图库EasyX
EasyX 什么是easyx? EasyX 是针对 C++ 的图形库,可以帮助 C++语言初学者快速上手图形和游戏编程.其实就是c++的一个图形库让初学者不用只在控制台输出代码,而是在图形界面进行开发 ...
- osworkflow 入门基础
OSWorkFlow入门指南目的 这篇指导资料的目的是介绍OSWorkflow的所有概念,指导你如何使用它,并且保证你逐步理解OSWorkflow的关键内容. 本指导资料假定你已经部署OSWorkfl ...