【POJ1811】Prime Test】的更多相关文章

[题目大意] 若n是素数,输出“Prime”,否则输出n的最小素因子,(n<=2^54) [题解] 和bzoj3667差不多,知识这道题没那么坑. 直接上Pollord_Rho和Rabin_Miller就行了. /************* POJ 1811 by chty 2016.11.7 *************/ #include<iostream> #include<cstdio> #include<cstdlib> #include<cstri…
[CF912E]Prime Game(meet in the middle) 题面 CF 懒得翻译了. 题解 一眼题. \(meet\ in\ the\ middle\)分别爆算所有可行的两组质数,然后二分答案,\(two-pointers\)扫一下就好了. #include<iostream> #include<cstdio> #include<algorithm> #include<vector> using namespace std; #define…
Description Given a big integer number, you are required to find out whether it's a prime number. Input The first line contains the number of test cases T (1 <= T <= 20 ), then the following T lines each contains an integer number N (2 <= N <…
题意:验证1~10000 的数 n^n+n+41 中素数的个数.每个询问给出a,b  求区间[a,b]中质数出现的比例,保留两位 题解:质数会爆到1e8 所以用miller robin , 另外一个优化是预处理 一个坑是四舍五入卡精度. #include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> #include<iostream> #include<…
http://poj.org/problem?id=3126 https://www.bnuoj.com/v3/problem_show.php?pid=3245 题目鬼图 刚开始看到题目的图觉得这题会很鬼,然后看题,发现是水题... 线性筛预处理素数→BFS+记录深度 or 迭代加深 or 分层BFS // <3126.cpp> - 11/01/16 17:31:53 // This file is made by YJinpeng,created by XuYike's black tec…
题目描述 设\(f(i)\)为\(i\)的不同的质因子个数,求\(\sum_{i=1}^n2^{f(i)}\) \(n\leq{10}^{12}\) 题解 考虑\(2^{f(i)}\)的意义:有\(f(i)\)总因子,每种可以分给两个人中的一个.那么就有\(2^{f(i)}=\sum_{d|i}[\gcd(d,\frac{i}{d})=1]\) 然后就是简单莫比乌斯反演了. \[ \begin{align} s&=\sum_{i=1}^n\sum_{d|i}[\gcd(d,\frac{i}{d}…
题目大意:求出一个给定区间 [l, r] 内相邻素数之间的最大距离和最小距离. 题解:由于 l, r 的范围太大,没法直接用筛法得出区间的素数.考虑筛出区间的素数等价于筛掉区间内的所有和数, 根据算术基本定理,若 \(x\in [l,r]\) 为和数,则 x 一定有一个小于 \(\sqrt(r)\) 的质因子,利用这条性质可知,只需预处理出十万以内的所有素数,并用这些素数去筛掉给定区间的和数即可. 代码如下 #include <bits/stdc++.h> #define fi first #…
#include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm> using namespace std; int n, m; const int N = 1e4 + 100; int vis[N]; struct node { int x, step; }; queue<node> Q; bool judge_prime(in…
vjudge 给定一棵边长都是\(1\)的树,求有多少条路径长度为质数 树上路径自然是点分治去搞,但是发现要求是长度为质数,总不能对每一个质数都判断一遍吧 自然是不行的,这个东西显然是一个卷积,我们合并的时候显然可以直接大力\(NTT\) 但是需要注意的是我们访问子树的顺序必须是先访问深度小的子树,否则轻松被菊花加长链卡掉 但是\(CodeChef\)数据水啊,就这样直接搞过去了 代码 #include<algorithm> #include<iostream> #include&…
Portal --> arc080_f Solution ​  这题的话..差分套路题(算吗?反正就是想到差分就很好想了qwq) ​​  (但是问题就是我不会这种套路啊qwq题解原话是:"这种翻面一段区间的题,就是差分套路题"==) ​  我们定义一个新的数组\(A\),\(A_i\)表示的是第\(i\)个和第\(i-1\)个的状态是否相同,是的话为\(0\)否则为\(1\),至于第\(0\)个的话..我们强行定义第\(0\)个位置反面向上 ​  这样我们就得到了一个\(01\)…