www.codechef.com/MAY15/problems/CHAPD

一道比较神奇的题目...

看到题目后自己yy出了个傻逼算法...然后对拍都是对的...提交都是错的...然后一看"Yes"打成"YES"了...= =!!人傻逼就是会犯脑残错误...

我的算法是$O\left(\log^2{n}\right)$的,但是实践中跑得很快...

这道题需要不多的数论知识= =...

我们设pf(x)={p|primes(p),p|x}

显然题目要求你判断$\mathtt{pf}(B)\subseteq \mathtt{pf}(A)$.

然后是比较奇怪的想法...我一开始就想到了,问了问LZW学长但是他没想到...

那么我们要判断的是$\mathtt{pf}\left(\gcd{A,B}\right)=\mathtt{pf}\left(B\right)$

我们记$C=\gcd{A,B}$

那么上面命题成立的充分必要条件是$\mathtt{pf}\left(\frac{B}{C}\right)\subseteq \mathtt{pf}\left(C\right)$

这个证明就yy一下好了,感觉挺好证的..

那么就可以递归求解了...

代码

#include <cstdio>
typedef long long ull;
ull a,b;
ull gcd(ull a,ull b){
return a?gcd(b%a,a):b;
}
bool isk(ull a,ull b){
ull c=gcd(a,b);
ull d=b/c;
if(c==1&&d!=1) return false;
if(d!=1ll) return isk(c,d);
return true;
}
int T;
int main(){
scanf("%d",&T);
while(T--){
scanf("%lld%lld",&a,&b);
if(isk(a,b)) printf("Yes\n"); else printf("No\n");
}
return 0;
}

CC MayClg 15 T3的更多相关文章

  1. 2019.2.15 t3 平均值

    #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #i ...

  2. Win7系统安装 Photoshop CC 中文完全破解版

    Win7系统安装 Photoshop CC 中文完全破解版 谨以此教程献给某位做UI设计的朋友^_^! 01. 确定自己的系统是32位的还是64位的,本人电脑是64位 02. 将 Photoshop_ ...

  3. linux awk命令学习

    . awk的运行过程 ) awk_script的组成: ① awk_script可以由一条或多条awk_cmd组成,两条awk_cmd之间一般以NEWLINE分隔 ② awk_cmd由两部分组成: a ...

  4. SQL表值函数(上月添加1-28)

    ALTER function [dbo].[fn_getdate3] ( ) ) RETURNS @Table_Var TABLE ( LastTime datetime ) as begin Dec ...

  5. Dreamweaver 升级问题汇总

    Adobe的产品开始从CC (Creative Cloud) 开始转向云平台,CS将逐渐成为过去时.不过CC并不限制用户在同一台机器上同时使用CS和CC,这种策略估计要持续较长一段时间. If you ...

  6. you-get中文说明

    来源于:https://github.com/soimort/you-get/wiki/%E4%B8%AD%E6%96%87%E8%AF%B4%E6%98%8E You-Get 乃一小小哒命令行程序, ...

  7. PHP和Golang使用Thrift1和Thrift2访问Hbase0.96.2(ubuntu12.04)

    目录: 一.Thrift1和Thrift2的简要介绍 1) 写在前面 2) Thrift1和Thrift2的区别  二.Thrift0.9.2的安装 1) 安装依赖插件 2) Thrift0.9.2的 ...

  8. MySQL Query Profile

    MySQL Query Profiler, 可以查询到此 SQL 语句会执行多少, 并看出 CPU/Memory 使用量, 执行过程 System lock, Table lock 花多少时间等等.从 ...

  9. Profiling MySQL queries from Performance Schema

    转自:http://www.percona.com/blog/2015/04/16/profiling-mysql-queries-from-performance-schema/ When opti ...

随机推荐

  1. Active-MQ的安装

    (1)首先就是下载软件 wget http://archive.apache.org/dist/activemq/apache-activemq/5.9.0/apache-activemq-5.9.0 ...

  2. 【BZOJ 3282】Tree Link Cut Tree模板题

    知道了为什么要换根(changeroot),access后为什么有时要splay,以及LCT的其他操作,算是比较全面的啦吧,,, 现在才知道这些,,,真心弱,,, #include<cstdio ...

  3. 负margin一些奇葩的布局技巧

    copy_from_ http://www.hicss.net/i-know-you-do-not-know-the-negative-margin/ <!doctype html> &l ...

  4. java.lang.NoClassDefFoundError: javax/transaction/UserTransaction

    在运行定时任务的时候报错: Java.lang.NoClassDefFoundError: javax/transaction/UserTransaction 原因:缺少jta的jar包 解决方法:下 ...

  5. BZOJ-4195 NOI2015Day1T1 程序自动分析 并查集+离散化

    总的来说,这道题水的有点莫名奇妙,不过还好一次轻松A 4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 836 ...

  6. ACdream 1429 Rectangular Polygon

    Rectangular Polygon Time Limit: 1000MS   Memory Limit: 256000KB   64bit IO Format: %lld & %llu D ...

  7. vim YouCompleteMe

    http://www.ithao123.cn/content-1906969.html http://www.it165.net/os/html/201503/12190.html

  8. 如果您想省略JS里的分号,了解一下JS的分号插入原理吧

    仅在}之前.一个或多个换行之后和程序输入的结尾被插入 也就是说你只能在一行.一个代码块和一段程序结束的地方省略分号. 也就是说你可以写如下代码 function square(x) { var n = ...

  9. PHP开发APP接口----单例模式连接数据库

    <?php //单例模式 class Db{ static private $_instance; static private $_connectSource; private $_dbCon ...

  10. tp三大自动

    ThinkPHP三大自动 (2012-03-21 10:48:56) 转载▼ 标签: thinkphp 三大自动 自动验证 自动完成 自动填充 自动映射 字段映射 杂谈 分类: php 一.自动验证 ...