题意: 求[a,b]之间的素数的个数 数很大...数组开不起 所以要想到转化 因为小于等于b的合数的最小质因子 一定小于等于sqrt(b),所以只需要求出来[0,sqrt(b)]的素数  然后取倍数删去[a,b]之间的合数  就好了 那  为什么小于等于b的合数的最小质因子 一定小于等于sqrt(b)呢? 因为b是最大的, 所以只讨论b即可 我们来看b的因子 ..一定是从 [0,sqrt(b)] 和 [sqrt(b),b]这两个区间里各取一个 先来看[0,sqrt(b)] 如果在这里取得是一个合…
http://lightoj.com/volume_showproblem.php?problem=1197 题目大意: 就是给你一个区间[a,b]让你求这个区间素数的个数 但a.b的值太大没法直接进行素数筛选(没法开那么大的数组),我们可以将a当做0,将b当做b-a 这样求[a,b]之间就变成了求[0, b - a]之间,这样就可以开数组来筛选 下图是代码式子j = j + prime[i] - a % prime[i]的由来 #include<stdio.h> #include<ma…
Help Hanzo (LightOJ - 1197) [简单数论][筛区间质数] 标签: 入门讲座题解 数论 题目描述 Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakurur…
http://poj.org/problem?id=2689 题意:给出一个大区间[L,U],分别求出该区间内连续的相差最小和相差最大的素数对. 由于L<U<=2147483647,直接筛素数是不行的,数组就开不了.可是能够依据素数筛的原理.我们先筛出sqrt(2147483647)以内的素数,然后拿这些素数去筛[L,U]之间的素数,即两次素数筛.可是L,U还是非常大,但U-L<=1000000,所以进行区间平移,将[L,U]平移为[0,U-L],就能用数组放得下. #include &…
题解:素数区间问题.注意到a和b的范围是1<<31,所以直接暴力打表肯定不可以.如果一个数是合数,他的两个因子要么是两个sqrt(x),要么就分布在sqrt(x)两端,所以我们可以根据sqrt(n)之前的数来把sqrt(n)之后的素数给筛出来. 首先进行1e6的素数打表.然后对每个l,r,首先找到第一个大于等于l的数,然后根据刚才的筛出来素数,一直累加,直到r为止,这样就可以把因子在1e6范围的合数给标记上了.注意我们保存的时候数组中要减去l,这样数组只要开到1e5就可以了.注意当l=1时,1…
Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19635   Accepted: 5273 Description The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number th…
E - Help Hanzo Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1197 Description Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he ha…
/** 题目:Help Hanzo lightof 1197 链接:https://vjudge.net/contest/154246#problem/M 题意:求一段区间内素数个数,[l,r] 在 [1,1e9] 范围内.r-l<=1e5; 思路:采用和平常筛素数的方法.平移区间即可. */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #i…
题目链接:https://vjudge.net/problem/LightOJ-1197 1197 - Help Hanzo    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he…
题意:筛一段区间内素数的个数,区间宽度10w,区间范围INT_MAX 分析:用sqrt(INT_MAX筛一遍即可),注意先筛下界,再筛上届,因为有可能包含 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <…