C程序中的订婚数?

c程序中的订婚数?

在这里我们将看到订婚号码。这是一对数字,其中一个数字的真因数之和比另一个数字多 1。我们必须找到这些对

例如,这对就像 (48, 75)。所以 48 的约数是 {1, 2, 3, 4, 6, 8, 12, 16, 24},和是 76。同样,75 的约数是 {1, 3, 5, 15, 25},所以和是 49。

算法

订婚对 (n) –

begin   for num in range 1 to n, do      sum := 1      for i in range 2 to num, do         if num is divisible by i, then            sum := sum + i            if i * i is not same as num, then               sum := sum + num / i            end if         end if         if sum > num, then            num2 := sum – 1            sum2 := 1            for j in range 2 to num2, do               if num2 is divisible by j, then                  sum2 := sum2 + j                  if j * j is not same as num2, then                     sum2 := sum2 + num2 / j                  end if               end if            done            if sum2 = num + 1, then               print the pair num and num2            end if         end if      done   doneend

登录后复制

示例

#include using namespace std;void BetrothedPairs(int n) {   for (int num = 1; num  num) {         int num2 = sum - 1;         int sum2 = 1;         for (int j = 2; j * j 

输出

1

登录后复制

以上就是C程序中的订婚数?的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2584193.html

(0)
上一篇 2025年3月6日 14:45:31
下一篇 2025年2月19日 02:24:54

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论