3 5 15
Case #1: 1 2 Case #2: 1 4 Case #3: 3 10 12 14HintIn the third sample, gcd(15,10)=5 and (15 xor 10)=5, gcd(15,12)=3 and (15 xor 12)=3,gcd(15,14)=1 and (15 xor 14)=1
#include <cstdio> #include <cmath> #define ll long long int const MAX = 1e5; ll fac[MAX], ans[MAX]; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { int ca = 1; ll n; while(scanf("%I64d", &n) != EOF) { int cnt1 = 0, cnt2 = 0; ll tmp = sqrt(n); for(ll i = 1; i <= tmp; i++) if(n % i == 0) fac[cnt1++] = i; for(ll i = tmp; i >= 1; i--) if(n % i == 0 && i != 1) fac[cnt1++] = n / i; for(int i = cnt1 - 1; i >= 0; i--) if(fac[i] == gcd(n, n^fac[i]) && (n^fac[i]) != 0 && (n^fac[i]) <= n) ans[cnt2++] = (n^fac[i]); printf("Case #%d:\n%d\n", ca++, cnt2); if(cnt2 == 0) printf("\n"); for(int i = 0; i < cnt2; i++) { if(i != cnt2 - 1) printf("%I64d ", ans[i]); else printf("%I64d\n", ans[i]); } } }
HDU 5175 Misaki's Kiss again (异或运算,公式变形)
原文地址:http://blog.csdn.net/tc_to_top/article/details/43822319