摘要: 筛出足够多的素数然后存起来查找即可。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 typedef long long ll; 8 const int N = 20000001; 9 const... 阅读全文
posted @ 2015-07-27 19:26 hxy_has_been_used 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 有整除关系就建边,然后求最大独立集。 AC代码: 阅读全文
posted @ 2015-07-27 18:48 hxy_has_been_used 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 经典尺取法,复杂度O(n)。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int INF = 999999; 7 const int N = 100000; 8 int a[N]; 9 10 int ma... 阅读全文
posted @ 2015-07-27 13:45 hxy_has_been_used 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 比较基本的数论题目,不过《挑战程序设计》上说这个题有不用幂运算求解的两种方法,一种复杂度为根号n,一种是O(n)预处理,O(1)判定,我还没有想出来....快速幂的方法: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 ... 阅读全文
posted @ 2015-07-27 12:54 hxy_has_been_used 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 由于区间的右端点非常大(INT_MAX),而区间长度相对小(100W),所以考虑区间筛法,左端点为1的情况需要特判一下。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 typedef long long ll; 7 c... 阅读全文
posted @ 2015-07-27 12:28 hxy_has_been_used 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 分为皇后在同一行、同一列、同一对角线的情况分别计数相加即可。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 typedef long long ll; 8 9 ll a( ll n, ll m... 阅读全文
posted @ 2015-07-27 10:09 hxy_has_been_used 阅读(157) 评论(0) 推荐(0) 编辑