当前位置: 首页>>代码示例>>C++>>正文


C++ sieve函数代码示例

本文整理汇总了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;
}
开发者ID:Cyborn13x,项目名称:SPOJ,代码行数:12,代码来源:COMDIV.cpp

示例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;
}
开发者ID:iamfelicio,项目名称:BI-PA1,代码行数:12,代码来源:seminar.c

示例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;
}
开发者ID:anttisalonen,项目名称:projecteuler,代码行数:12,代码来源:main.cpp

示例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;
}
开发者ID:Pedromdrp,项目名称:project-euler,代码行数:12,代码来源:circular_primes.c

示例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;
}
开发者ID:eokeeffe,项目名称:C-code,代码行数:12,代码来源:bitsets.c

示例6: main

int main()
{
int t;
sieve();
scanf("%d",&t);
while(t--)
{
scanf("%ld",&j);
printf("%ld\n",pos[j]);
}
return 0;
}
开发者ID:1mSatyam,项目名称:spoj-solutions,代码行数:12,代码来源:TDKPRIME.cpp

示例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]);
  }
}
开发者ID:mkirsche,项目名称:project-euler,代码行数:12,代码来源:prime_test.cpp

示例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;
}
开发者ID:Sayem-Mohammad-Imtiaz,项目名称:competitive-programming,代码行数:12,代码来源:11960_3.cpp

示例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;
}
开发者ID:sarker306,项目名称:Codeforces,代码行数:12,代码来源:codeforces236C.c

示例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;
}
开发者ID:sblackstone,项目名称:project_euler_solutions,代码行数:57,代码来源:segmented_sieve.cpp

示例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;
}
开发者ID:JohnXinhua,项目名称:UVa,代码行数:17,代码来源:1434+-+YAPTCHA.cpp

示例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;
}
开发者ID:Mercerenies,项目名称:eulers-melting-pot,代码行数:13,代码来源:problem60_3.cpp

示例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);
}
开发者ID:robertdfrench,项目名称:paratosthenes,代码行数:13,代码来源:mpi_sieve.c

示例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);
    }
}
开发者ID:abhayprakash,项目名称:competitive_programming,代码行数:13,代码来源:FINDPRM-8664689-src.cpp

示例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;
}
开发者ID:rgiesler,项目名称:projectEulerSolutions_C,代码行数:22,代码来源:problem12.c


注:本文中的sieve函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。