#题目:GCD XOR UVA - 12716

本文探讨了一道关于寻找满足特定条件的整数对的数学问题,即当两个数的最大公约数等于这两个数的异或值时,如何在一定范围内找出所有符合条件的数对。文章分享了解题思路,包括利用异或的性质和通过筛法优化计算过程,并提供了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

Given an integer N, find how many pairs (A, B) are there such that: gcd(A, B) = A xor B where
1 ≤ B ≤ A ≤ N.
Here gcd(A, B) means the greatest common divisor of the numbers A and B. And A xor B is the
value of the bitwise xor operation on the binary representation of A and B.

input
The first line of the input contains an integer T (T ≤ 10000) denoting the >number of test cases. The
following T lines contain an integer N (1 ≤ N ≤ 30000000).
output
For each test case, print the case number first in the format, ‘Case X:’ (here, X is the serial of the
input) followed by a space and then the answer for that case. There is no new-line between cases.
Sample Input
2
7
20000000
Sample Output
Case 1: 4
Case 2: 34866117

题意:

多组数据输入,每组数据输入一个n,问在小于n的数字里面能找到多少对数满足gcd(a,b)==a^b(大于b)

解题思路:

根据异或的性质我们可以发现,a^gcd(a,b)=b;
而gcd(a,b)又是a的约数,所以我们可以枚举c,就可以像筛素数那样做,然后在暴力小数据打表的时候发现gcd(a,b)=a-b,证明详见紫书318页。所以我们在筛的时候就找a^(a-b)是否等于b就行

代码

#include <iostream>
using namespace std;

int gcd (int a,int b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
int a[300000005];

void init()
{
    a[1]=0;
    a[2]=0;

    for(int i=1;i<300000007;i++)
    {
        for(int j=i+i;j<30000007;j+=i)
        {
            int tmp = j-i;
            if((j^tmp) == i)
            {
                a[j]++;
            }

        }
        a[i]+=a[i-1];
    }


}

int main()
{
   init();
   int t;
   cin>>t;
   int flg=1;
   while(t--)
   {
    int n;
    cin>>n;
    int ans=a[n];
    cout<<"Case "<<flg++<<": "<<ans<<endl;

   }
   return 0;
}

总结:

要多去想规律,比如说看到异或就要想到:如果a^b=c那么a^c=b,然后还要结合打表。

转载于:https://www.cnblogs.com/IAMjm/p/9429146.html

### 判断 S5700 交换机端口聚合配置完成的关键依据 #### 状态信息解析 在 S5700 交换机上,配置完成后可以通过以下关键状态信息判断端口聚合是否成功: 1. **Eth-Trunk 的操作状态** 使用 `display eth-trunk` 命令查看 Eth-Trunk 的详细信息。如果 Eth-Trunk 的 `Operate status` 显示为 `up`,则表明该聚合链路已正常工作[^3]。 2. **成员端口的状态** 在 Eth-Trunk 的输出信息中,检查 `Number Of Up Port In Trunk` 字段。此字段表示当前处于活动状态的成员端口数量。如果所有配置的成员端口状态均为 `up`,则说明这些端口已成功加入聚合链路[^3]。 3. **LACP 协商状态** 如果使用的是动态模式(LACP),可以通过命令 `display lacp statistics eth-trunk [number]` 检查 LACP 报文的收发情况。正常情况下,LACP 报文的收发计数应不断增加,表明两端设备成功建立了聚合链路[^1]。 4. **负载均衡算法** 在 Eth-Trunk 的信息中,检查 `Hash arithmetic` 字段,确认使用的负载均衡算法是否符合预期设置。例如,根据源 IP 和目标 IP 进行哈希计算的算法应显示为 `According to SIP-XOR-DIP`[^2]。 #### 示例输出分析 以下是一个典型的 Eth-Trunk 配置验证输出示例: ```plaintext [SW1] display eth-trunk 1 Eth-Trunk1&#39;s state information is: WorkingMode: NORMAL Hash arithmetic: According to SIP-XOR-DIP Least Active-linknumber: 1 Max Bandwidth-affected-linknumber: 8 Operate status: up Number Of Up Port In Trunk: 2 ---------------------------------------------------------------------------- PortName Status Weight GigabitEthernet0/0/9 Up 1 GigabitEthernet0/0/10 Up 1 ``` 从上述输出可以看出,Eth-Trunk1 已经正常工作,且包含两个活动成员端口。`Operate status` 为 `up`,表明聚合链路处于活动状态。 #### 测试冗余性 为了进一步验证端口聚合的冗余性,可以断开一个成员接口或整个 Eth-Trunk 口并观察网络通信是否仍然正常。例如,关闭 SW1 的一个 Eth-Trunk 口: ```bash [SW1]int Eth-Trunk 1 [SW1-Eth-Trunk1]shutdown ``` 如果网络通信仍然正常,则表明端口聚合的冗余功能已正确配置[^1]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值