예제 #1
0
파일: 406.cpp 프로젝트: Accoral/uva
int main()
{
	//cout << sqrt ( 1000 ) << endl;
	prime_sieve ( );
	int n, c, from, to, len, i;
	while ( scanf ( "%d%d", &n, &c ) != EOF ) {
		printf ( "%d %d:", n, c );
		len = upper_bound ( primes.begin(), primes.end(), n ) - primes.begin();
		if ( len&1 ) from = len/2-(c-1), to = len/2+(c-1);
		else from = len/2-c, to = len/2+(c-1);
		from = max ( 0, from ); to = min ( len-1, to );
		for ( i = from; i < to; ++i ) printf ( " %d", primes[i] );
		printf ( " %d\n\n", primes[i] );
	}
    return 0;
}
예제 #2
0
파일: fill.cpp 프로젝트: asifcse10/pc-code
// Returns the number of containers required to move all the milk, with at
// most "c" in each container
int f(int c)
{
    int ret = 0;
    IVi it = acap.begin();

    int lim = c;
    while (true) {
        if (*it > lim) return INF;
        it = upper_bound(it, acap.end(), lim);
        ++ret;
        if (it == acap.end()) return ret;
        lim = *(it - 1) + c;
    }
    return -1;
}
예제 #3
0
파일: gen.cpp 프로젝트: M4573R/pc-code
void test_case()
{
    int n = rand() % (MAXN - 2) + 3;
    int MaxEdges = min(n*(n-1)/2, MAXM);
    int m = rand() % (MaxEdges + 1);

    if (m < n - 1) m = n - 1;

    printf("\n%d %d\n", n, m);

    IV ls;
    IIS s;
    for (int i = 0; i < n; ++i)
        ls.push_back(i);
    random_shuffle(ls.begin(), ls.end());

    printf("%d %d\n", ls[0], ls[1]); --m;
    int u = ls[0], v = ls[1];
    if (u > v) swap(u, v);
    s.insert(II(u, v));

    for (int i = 2; i < n; ++i) {
        u = ls[rand() % i], v = ls[i];
        printf("%d %d\n", u, v); --m;
        if (u > v) swap(u, v);
        s.insert(II(u, v));
    }

    while (m--) {
        int u, v;
        do {
            u = rand() % n;
            v = rand() % n;
            if (u > v) swap(u, v);
        } while (u == v || s.find(II(u, v)) != s.end());

        s.insert(II(u, v));

        if (rand() % 2 == 0) swap(u, v);
        printf("%d %d\n", u, v);
    }
}
예제 #4
0
파일: 10311.cpp 프로젝트: Accoral/uva
int main()
{
	prime_sieve ( );
	int x, ok;
	while ( scanf ( "%d", &x ) != EOF ) {
		ok = 1;
		if ( x < 5 ) printf ( "%d is not the sum of two primes!\n", x );
		else if ( x & 1 ) {
			if ( is_prime(x-2) ) printf ( "%d is the sum of %d and %d.\n", x, 2, x-2 );
			else printf ( "%d is not the sum of two primes!\n", x );
		}
		else {
			IV :: iterator it = upper_bound ( primes.begin(), primes.end(), x/2 );
			for ( ; it != primes.end(); ++it )
				if ( is_prime(x-*it) ) {
					printf ( "%d is the sum of %d and %d.\n", x, x-*it, *it );
					ok = 0;
					break;
				}
			if ( ok ) printf ( "%d is not the sum of two primes!\n", x );
		}
	}
    return 0;
}