HDU5175Misaki's Kiss again——数论

http://acm.split.hdu.edu.cn/showproblem.php?pid=5175

若gcd(a,b)= a xor b=c,则b=a-c (打表发现的)

c是a的因子,则枚举a的所有因子判断b是否满足a^b=c
93MS 1104K 893 B

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
ll n;
vector<ll> vl;
int main()
{
    int Case=1;
    while(scanf("%I64d",&n)!=EOF){
        vl.clear();
        printf("Case #%d:\n", Case++);
        for(ll c=1;c*c<=n;++c){
            if(n%c==0){
                ll b=n-c;
                if( b>0&&(n^b)==c){
                    vl.push_back(b);
                }
                if(n/c!=c){
                    b=n-n/c;
                    if(b>0&&b<=n&&((n^b)==(n/c))) vl.push_back(b);
                }
            }
        }
        sort(vl.begin(),vl.end());
        printf("%d\n",vl.size());
        for(int i=0;i<vl.size();++i){
            printf("%I64d",vl[i]);
            if(i!=vl.size()-1) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(HDU5175Misaki's Kiss again——数论)