【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. ...
随机推荐
- 完全删除MySQL及相关软件
一.删除mysql服务 个人认为首先删除mysql服务最重要,这个多数人会忘记如何删除 首先是查看自己的mysql服务名,需要用这个服务名进行删除 进入命令行 二.卸载mysql,workbench等 ...
- [BZOJ 3117] [NOI1999]内存分配(STL)
[BZOJ 3117] [NOI1999]内存分配(STL) 题面 内存是计算机重要的资源之一,程序运行的过程中必须对内存进行分配. 经典的内存分配过程是这样进行的: 1.内存以内存单元为基本单位,每 ...
- const和static const的区别(未整理)
对于C/C++语言来讲,const就是只读的意思,只在声明中使用;static一般有2个作用,规定作用域和存储方式.对于局部变量,static规定其为静态存储方式,每次调用的初始值为上一次调用的值,调 ...
- jquery的ajax方法使用application/json出现400错误码的解决方案
400说明是客户端错误,将contentType默认的application/x-www-form-urlencoded改成application/json就出现错误,说明传输的数据不是JSON. 解 ...
- git删除已经push的远程文件或文件夹
在使用git提交项目时,有时候会误提交一下文件,比如:*.iml,*.project,*.settings,.idea/*等文件,有时候这些不需要提交的文件可以加入到.gitignore,在提交的时候 ...
- java实现的LinkedLilst
package javabean.adt.List; import java.util.ConcurrentModificationException; import java.util.Iterat ...
- [转载]ubuntu常用命令
1.帮助 --help简单的帮助 help command 较详细的帮助 man command 最详细的帮助2.ls 命令 ls -a 显示全部的文件及文件夹 ...
- openstack dashboard开启https
前提条件: 1.基于http的dashboard能正常访问 2.拥有ssl证书 第一步:修改/etc/openstack-dashboard/local_settings 在DEBUG = False ...
- 模块之time与datetime
模块之time与datetime import time print (time.clock()) print(time.process_time()) #测量处理器运算时间 print(time.a ...
- 表单的 submit 和 onsubmit 的用法 与区别
submit与onsubmit 发生顺序:onsubmit -> submit 1.阻止表单提单: <script>function submitFun(){ //逻辑判断 ...