UVa 10880 - Colin and Ryan

来源:互联网 发布:淘宝投诉不成立怎么办 编辑:程序博客网 时间:2024/05/29 19:12

有n块饼干,请G个客人,每个客人吃Q块饼干,要求最后剩m块。

思路:只要求出n-m这个数的因子就好,每个因子代表可以请几个客人,但是要满足要求,Q>m,最后要求出去Q,从小到大的顺序

 

/*************************************************************************    > File Name: 10880.cpp    > Author: Toy    > Mail: ycsgldy@163.com    > Created Time: 2013年06月07日 星期五 16时00分58秒 ************************************************************************/#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <cstdlib>#include <climits>#include <sstream>#include <fstream>#include <cstdio>#include <string>#include <vector>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>using namespace std;const int INF = 0x7fffffff;typedef pair<int,int> II;typedef vector<int> IV;typedef vector<II> IIV;typedef vector<bool> BV;typedef long long i64;typedef unsigned long long u64;typedef unsigned int u32;#define For(t,v,c) for(t::const_iterator v=c.begin(); v!=c.end(); ++v)#define IsComp(n) (_c[n>>6]&(1<<((n>>1)&31)))#define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31))const int MAXP = 46341; //sqrt(2^31)const int SQRP = 216; //sqrt(MAX)int _c[(MAXP>>6)+1];IV primes, opt, vec;int Case, n, m;void prime_sieve (){    for ( int i = 3; i <= SQRP; i += 2 )        if ( !IsComp ( i ) ) for ( int j = i * i; j <= MAXP; j += i + i ) SetComp ( j );    primes.push_back( 2 );    for ( int i = 3; i <= MAXP; i += 2 )        if ( !IsComp ( i ) ) primes.push_back( i );}void divisors ( int n, IV &ds ) {    ds.clear ( );    ds.push_back ( 1 );    int sn = sqrt ( n );    For ( IV, it, primes ) {        int p = *it;        if ( p > sn ) break; if ( n % p != 0 ) continue;        IV aux ( ds.begin (), ds.end() );        int q = 1;        while ( n % p == 0 ) {            q *= p; n /= p;            For ( IV, v, ds ) aux.push_back( ( *v * q ) );        }        sn = sqrt ( n ); ds = aux;    }    if ( n > 1 ) {        IV aux ( ds.begin(), ds.end() );        For ( IV, v, ds ) aux.push_back( *v * n );        ds = aux;    }}int main ( ) {    prime_sieve ();    scanf ( "%d", &Case );    for ( int cnt = 1; cnt <= Case; ++cnt ) {        scanf ( "%d%d", &n, &m );        printf ( "Case #%d:", cnt );        if (  m == n ) printf ( " 0" );        else {            vec.clear();            int R = n - m;            divisors( R, opt );            For ( IV, it, opt ) {                if ( ( R / *it ) > m ) vec.push_back ( R / *it );            }            sort ( vec.begin (), vec.end () );            For ( IV, it, vec )                printf ( " %d", *it );        }        printf ( "\n" );    }    return 0;}


 

 

 

原创粉丝点击