本文整理汇总了C++中sieve函数的典型用法代码示例。如果您正苦于以下问题:C++ sieve函数的具体用法?C++ sieve怎么用?C++ sieve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sieve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
int test, a, b, g;
fread(buff, 1, 14000000, stdin);
sieve();
test = nextint();
while(test--) {
a = nextint(), b = nextint();
g = gcd(a, b);
printf("%d\n", cntdiv(g));
}
return 0;
}
示例2: main
int main(int argc, const char * argv[]) {
reverse();
sieve(5);
printf("gcd: %d\n", gcd(gcd(72, 48), 54));
printf("lcm: %d\n", lcm(lcm(6, 8), 15));
printf("%d\n", fibonacciNumber3(5));
return 0;
}
示例3: solve
int solve(ull_t n)
{
auto primes = sieve(n);
ull_t primes_sum = 0;
for(auto& p : primes) {
primes_sum += p;
}
printf("Sum of primes up to %llu = %llu\n", n, primes_sum);
printf("Largest found prime: %llu\n", primes.back());
check_result(n == 10, primes_sum == 17);
return 0;
}
示例4: count_circular
unsigned count_circular() {
char primes[LIMIT];
unsigned counter = 0;
int i;
sieve(primes, LIMIT);
for (i = 0; i < LIMIT; ++i) {
if (primes[i] && is_circular(primes, i)) {
++counter;
}
}
return counter;
}
示例5: main
main()
{
char bitarray[BITNSLOTS(47)];
BITSET(bitarray, 23);
BITCLEAR(bitarray, 14);
if(BITTEST(bitarray, 35))
printf("yep\n");
else printf("nope\n");
sieve();
return 0;
}
示例6: main
int main()
{
int t;
sieve();
scanf("%d",&t);
while(t--)
{
scanf("%ld",&j);
printf("%ld\n",pos[j]);
}
return 0;
}
示例7: TEST
TEST(primes, sieve) {
int n = 100;
bool under_test[n];
sieve(under_test, n);
int i;
for (i = 2; i < n; i++) {
EXPECT_EQ(is_prime(i), under_test[i]);
}
}
示例8: main
int main()
{
long kase,i,n;
sieve(112000);
scanf("%ld",&kase);
while(kase--)
{
scanf("%ld",&n);
printf("%ld\n",d[n]);
}
return 0;
}
示例9: main
int main(){
long n;
int ans[10] = {0, 1, 2, 6, 12, 60};
sieve();
while ( scanf("%ld", &n) != EOF ){
if ( n < 6 ) printf("%d\n", ans[n]);
else printf("%I64d\n", findLCM(n));
}
return 0;
}
示例10: segmented_sieve
/// Generate primes using the segmented sieve of Eratosthenes.
/// This algorithm uses O(n log log n) operations and O(sqrt(n)) space.
/// @param limit Sieve primes <= limit.
/// @param segment_size Size of the sieve array in bytes.
///
void segmented_sieve(int64_t limit, int segment_size = L1D_CACHE_SIZE)
{
int sqrt = (int) std::sqrt((double) limit);
int64_t count = (limit < 2) ? 0 : 1;
int64_t s = 2;
int64_t n = 3;
// vector used for sieving
std::vector<char> sieve(segment_size);
// generate small primes <= sqrt
std::vector<char> is_prime(sqrt + 1, 1);
for (int i = 2; i * i <= sqrt; i++)
if (is_prime[i])
for (int j = i * i; j <= sqrt; j += i)
is_prime[j] = 0;
std::vector<int> primes;
std::vector<int> next;
for (int64_t low = 0; low <= limit; low += segment_size)
{
std::fill(sieve.begin(), sieve.end(), 1);
// current segment = interval [low, high]
int64_t high = std::min(low + segment_size - 1, limit);
// store small primes needed to cross off multiples
for (; s * s <= high; s++)
{
if (is_prime[s])
{
primes.push_back((int) s);
next.push_back((int)(s * s - low));
}
}
// sieve the current segment
for (std::size_t i = 1; i < primes.size(); i++)
{
int j = next[i];
for (int k = primes[i] * 2; j < segment_size; j += k)
sieve[j] = 0;
next[i] = j - segment_size;
}
for (; n <= high; n += 2)
if (sieve[n - low]) // n is a prime
count++;
}
std::cout << count << " primes found." << std::endl;
}
示例11: main
// if 3k+7 is not a prime, 3k+7 = a*b, then a, b <= 3k+6,
// we get (3k+7) | (3k+6)!, so item = 0
// if 3k+7 is prime, (3k+7) | (3k+6)!+1 by Wilson's theorem
// so item = 1
int main() {
sieve();
for (int i = 1; i < 1048576; i++)
S[i] = S[i-1] + (GET(3 * i + 7) == 0);
int testcase, n;
scanf("%d", &testcase);
while (testcase--) {
scanf("%d", &n);
printf("%d\n", S[n]);
}
return 0;
}
示例12: main
int main() {
constexpr long long SIZE = 5;
std::array<long long, SIZE> curr;
long long bound = 9999;
long long result = bound * SIZE;
while (result >= bound * SIZE) {
sieve(std::max<long long>(bound * 10, 99999999));
result = seek_seq<SIZE>(curr, 0, bound);
bound *= 5;
}
std::cout << result << std::endl;
}
示例13: top_main
void top_main(int rank) {
int primes[3];
primes[0] = 2;
primes[1] = 3;
primes[2] = 5;
printf("Hello from the top\n");
fflush(stdout);
int* composites = (int*)malloc(sizeof(int) * 100);
initialize_range(composites, 100, 6);
sieve(primes, 3, composites, 100);
drop_ints(composites, 100);
}
示例14: main
int main()
{
int t,n;
int ans=0;
sieve();
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ans=primeno[n]-primeno[n/2];
printf("%d\n",ans);
}
}
示例15: main
int main(int argc, char *argv[])
{
int number = 0, i = 1; // number is triangle number, i is current term
int sizeOfPrimes = 1000, sizeOfPrimesSqr = 1000000;
int *primes;
int numPrimes = sieve(sizeOfPrimes, &primes);
while(numDivisors(number, primes, numPrimes) < 500) {
if(sizeOfPrimesSqr < number) { // Update if it becomes too small
sizeOfPrimes *= 5;
sizeOfPrimesSqr = sizeOfPrimes*sizeOfPrimes;
numPrimes = sieve(sizeOfPrimes, &primes);
}
number += i++; // Increment number
}
printf("Triangle number: %d\n", number);
free(primes);
return 0;
}