zoukankan      html  css  js  c++  java
  • UVA 12716 GCD XOR(GCD等于XOR)(数论)

    题意:输入整数n(1<=n<=30000000),有多少对整数(a, b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b。

    分析:因为c是a的约数,所以枚举c,a = k*c,通过a-c求b,并通过a^b=c来验证。

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    const double eps = 1e-8;
    inline int dcmp(double a, double b){
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 30000000 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int ans[MAXN];
    void init(){
        for(int c = 1; c <= (MAXN >> 1); ++c){
            for(int a = c + c; a <= MAXN; a += c){
                int b = a - c;
                if((a ^ b) == c) ++ans[a];
            }
        }
        for(int i = 2; i <= MAXN; ++i){
            ans[i] += ans[i - 1];
        }
    }
    int main(){
        init();
        int T;
        scanf("%d", &T);
        int kase = 0;
        while(T--){
            int n;
            scanf("%d", &n);
            printf("Case %d: %d\n", ++kase, ans[n]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    sort,uniq,wc,tr
    cut
    more,less,head,tail
    cat
    mv
    WordPress调用全文阅读和截取文章摘要
    板邓:css ol 列表序列号样式
    小板邓:wordpress如何扩展TinyMCE编辑器,添加自定义按钮及功能
    wordpress前台显示顶部管理工具导航条
    SQL的主键和外键的作用
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6387953.html
Copyright © 2011-2022 走看看