查找 A、B 和 C 的值,使得 (A^B)+(B^C)+(C^A) 等于给定整数 X

发布于 2025-01-20 03:31:20 字数 105 浏览 2 评论 0原文

X 是正整数。我必须找到 3 个不同的数字 A、B 和 C,使得 0 ≤ A,B,C < 230 和 (A^B)+(B^C)+(C^A)=X,其中“^”是按位异或运算符

X is positive integer.I have to find 3 distinct numbers A, B and C such that 0 ≤ A,B,C < 230 and (A^B)+(B^C)+(C^A)=X where '^' is a bitwise XOR operator

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

调妓 2025-01-27 03:31:20

免责声明:我不是数学家。

有多种解决方案,本文找到其中之一。

  1. 获取 X 并将其转换为二进制(例如 20220408 - 昨天的日期)

    X=1001101001000100111111000

  2. 如果最后一位数字为 1(X 为奇数),则无解

  3. 丢弃最后的0(除以2或右移)

    X=100110100100010011111100

  4. 创建 3 个二进制数:从零开始,并将 X 中的每 1 位放入 a 或 b 或 c。哪一个并不重要。只是为了好玩,让我们以循环方式进行:

    a=100000100000000010010000

    b=000100000100000001001000

    c=000010000000010000100100

    注意:如果只有一个 1 位(X 是 2 的幂),a,b,c 不会不同,因为其中 2 个为零。

检查结果:

a=int('100000100000000010010000', 2)
b=int('000100000100000001001000', 2)
c=int('000010000000010000100100', 2)
print((a^b)+(b^c)+(c^a)) # 20220408

Disclaimer: I'm not an mathematician.

There are several solutions, this finds one of them.

  1. take the X and convert it to binary (e.g 20220408 - yesterday's date)

    X=1001101001000100111111000

  2. If the last digit is 1 (X is odd), there is no solution

  3. Discard the last 0 (divide by 2 or shift right)

    X=100110100100010011111100

  4. Create 3 binary numbers: start with zeroes and put each 1 bit from X to either a or b or c. It does not matter which one. Just for fun let's do it in a round-robin matter:

    a=100000100000000010010000

    b=000100000100000001001000

    c=000010000000010000100100

    Note: if there is only one 1 bit (X is a power of 2), a,b,c won't be distinct, because 2 of them will be zero.

Check the result:

a=int('100000100000000010010000', 2)
b=int('000100000100000001001000', 2)
c=int('000010000000010000100100', 2)
print((a^b)+(b^c)+(c^a)) # 20220408
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文