标签:
题目大意:
After the Ferries Wheel, many friends hope to receive the Misaki‘s kiss again,so Misaki numbers them
Please help Misaki to find all
Note that:
解题思路:
gcd(N,M) == N XOR M ,则 N XOR M 是 N的一个约数,枚举N的所有约数,然后求GCD判断。
#include <iostream> #include <cstring> #include <cstdlib> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #define LL long long using namespace std; const int maxn = 10000000 + 10; LL ans[maxn]; LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); } int main() { LL N; int kcase = 1; while(scanf("%I64d", &N)!=EOF) { LL sum = 0; LL R = (LL)(sqrt(N + 0.5)); for(LL i=1;i<=R;i++) { if(N % i == 0) { if((N ^ i) >=1 && (N ^ i) <= N && gcd((N ^ i),N) == i) ans[++sum] = (N ^ i); if(i != N / i) { LL x = N / i; if((N ^ x)>=1 && (N ^ x) <= N && gcd((N ^ x),N)==x) ans[++sum] = (N ^ x); } } } printf("Case #%d:\n", kcase++); printf("%I64d\n", sum); sort(ans+1,ans+1+sum); if(sum > 0) { printf("%I64d", ans[1]); for(int i=2;i<=sum;i++) printf(" %I64d", ans[i]); } printf("\n"); } return 0; }
HDU 5175 Misaki's Kiss again(数学,暴力枚举)
标签:
原文地址:http://blog.csdn.net/moguxiaozhe/article/details/43865875