http://acm.hdu.edu.cn/showproblem.php?pid=5255
枚举a和c 求解b
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <algorithm>
using namespace std ; typedef long long LL ; #define clr( a , x ) memset ( a , x , sizeof a )
#define ls ( o << 1 )
#define rs ( o << 1 | 1 )
#define lson ls , l , m
#define rson rs , m + 1 , r
#define mid ( ( l + r ) >> 1 )
#define root 1 , 1 , n const int L = ; LL p[] ;
LL S[L] , top ; LL gcd ( LL a , LL b ) {
return b ? gcd ( b , a % b ) : a ;
} LL f ( LL pp , LL a , LL c , LL x1 , LL y1 ) {
LL x = a * pp * x1 - c * pp * y1 + c * x1 - a * y1 ;
LL y = ( y1 - x1 ) * ;
if ( x == ) return ;
else if ( x > && y < || x < && y > ) return - ;
else {
if ( x % y ) return - ;
else return x / y ;
}
} char s[] ; void solve () {
int x = , y = , loc = ;
top = ;
scanf ( "%s" , s ) ;
int n = strlen ( s ) ;
for ( int i = ; i < n ; ++ i ) {
if ( s[i] >= '' ) {
x = x * + s[i] - '' ;
if ( loc ) y *= ;
} else loc = ;
}
int g = gcd ( x , y ) ;
int x1 = x / g ;
int y1 = y / g ;
for ( int i = ; i <= ; ++ i ) {
for ( int a = ; a <= ; ++ a ) {
for ( int c = ; c <= ; ++ c ) {
LL b = f ( p[i] , a , c , x1 , y1 ) ;
if ( b < || b * >= p[i] ) continue ;
LL t = a * p[i] + b * + c ;
S[top ++] = t ;
}
}
}
printf ( "%d\n" , top ) ;
sort ( S , S + top ) ;
for ( int i = ; i < top ; ++ i ) {
printf ( "%I64d%c" , S[i] , i < top - ? ' ' : '\n' ) ;
}
} int main () {
int T ;
p[] = ;
for ( int i = ; i <= ; ++ i ) {
p[i] = p[i - ] * ;
}
scanf ( "%d" , &T ) ;
for ( int i = ; i <= T ; ++ i ) {
printf ( "Case #%d:\n" , i ) ;
solve () ;
}
return ;
}