SDUT 2809 Goldbach

Goldbach

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

The Goldbach’s Conjecture is stated like the following:
Every even number greater than 4 can be written as the sum of two odd prime numbers.
Your task is now to verify Goldbach\'s Conjecture for all even numbers less than a million.

输入

The input contains multiple test cases. Each test case consisted of an even integer n with 6 < n < 1000000. Input will be terminated by 0.

输出

For every test case, print one line of the form “n = a + b”, a < b, without quotes. Where a and b are odd prime numbers. If there is more than one pair of odd primes, you are to print the pair a, b with the maximized difference b - a. If there are no such pair, print a line saying “Goldbach\'s conjecture is wrong.”.

示例输入

8
20
0

示例输出

8 = 3 + 5
20 = 3 + 17

#include <bits/stdc++.h>

using namespace std;

bool prim(int n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}

int main()
{
    int n;
    while(cin>>n && n)
    {
        for(int i=2;i<=n/2;i++)
        {
            if(prim(i))
            {
                int t = n - i;
                if(prim(t))
                {
                    cout<<n<<" = "<<i<<" + "<<t<<endl;
                    break;
                }
            }
        }
    }
    return 0;






### 关于Python与SDUT的相关信息 #### Python在SDUT的应用 山东理工大学(Shandong University of Technology, SDUT)在其ACM在线评测系统中提供了大量基于Python的编程题目,这些题目涵盖了基础算法、数据结构以及面向对象编程等多个方面。通过解决这些问题,学生可以提升自己的编程能力并熟悉Python语言的核心特性[^1]。 #### 提供的具体实例分析 以一道典型的输入输出练习为例,展示了如何利用`while`循环读取多组测试数据直到遇到特定终止条件为止。此方法非常适合处理批量计算场景下的逻辑实现: ```python while True: s = input().split() if int(s[0]) == 0 and int(s[1]) == 0: break print(int(s[0]) + int(s[1])) ``` 上述代码片段实现了连续求两数之和的功能,并在两个输入均为零时结束程序运行。这体现了Python简洁优雅的特点及其强大的字符串操作功能。 #### 面向对象实践案例 另一个例子涉及定义矩形类来完成几何图形属性的操作,如下所示: ```python class Rect: def __init__(self, x, y): if x <= 0 or y <= 0: self.x, self.y = 0, 0 else: self.x, self.y = x, y def length1(self): return self.x * 4 def area1(self): return self.x ** 2 def length2(self): return (self.x + self.y) * 2 def area2(self): return self.x * self.y try: l = list(map(int, input().split())) if len(l) == 1: a = Rect(l[0], 1) print(a.x, a.x, a.length1(), a.area1()) elif len(l) == 2: a = Rect(l[0], l[1]) print(a.x, a.y, a.length2(), a.area2()) except: pass ``` 该脚本不仅巩固了基本算术运算的知识点,还引入了异常捕获机制确保程序健壮性[^3]。 #### 数学运算综合应用 对于简单的数值型任务如三数加总、相乘及均值计算,则有以下解决方案展示精确控制浮点显示的方式[^4]: ```python a, b, c = map(int, input().split()) x = a + b + c y = a * b * c z = x / 3 print(f"{x} {y} {z:.2f}") ``` 这段代码清晰明了地完成了指定格式化输出的要求,同时运用到了现代f-string技术简化模板替换过程。 ### 总结 综上所述,无论是初学者还是有一定经验的学习者都能从SDUT所提供的资源中学到实用技能。它覆盖范围广泛,既包括简单概念也包含复杂理论的实际运用情况介绍。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值