zoukankan      html  css  js  c++  java
  • 例10-5 uva12716

    题意:gcd(a,b) = a^b,( 1≤ a , b ≤ n)

    思路:

    ① a^b = c, 所以 a^c = b,而且c是a的约数,枚举a,c,再gcd判断

    ② 打表可知 a-b = c,而且a ^ b = c,枚举c及其倍数a,判断一下即可。

    最开始用第一种,感觉太慢了- -,完全卡住了,可能方法不到位吧

    然后尝试了下②,因为c是a的约数,先枚举c,然后用类似素数筛选的方法。


    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <vector>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    
    const int maxn = 30000000;
    int ans[maxn];
    
    
    void get()
    {
        for(int c = 1; c <= maxn/2; c++)
        {
            for(int a = c+c; a <= maxn; a += c)
            {
                if(((a-c)^a) == c)
                {
                    ans[a]++;
                }
            }
        }
        for(int i = 2;i <= maxn;i++)
        {
            ans[i] += ans[i-1];
        }
    }
    
    int main()
    {
        get();
        int T,cas = 1,n;
        scanf("%d",&T);
        while(T--)
        {
    
            scanf("%d",&n);
            printf("Case %d: ",cas++);
            printf("%d
    ",ans[n]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    利用ssh传输文件
    linux 终端常用快捷键
    ubuntu 下关闭apache服务自动启动
    linux ps命令介绍
    virtualenv 使用
    startuml 2.6注册
    三代组装小基因组研究综述
    畅想未来的测序
    测序简史
    纳米孔测序技术介绍
  • 原文地址:https://www.cnblogs.com/Przz/p/5409718.html
Copyright © 2011-2022 走看看