缘由c语言多循环问题!-CSDN论坛
进行哥德巴赫猜想的验证时,不能判断202以上的偶数-编程语言-CSDN问答
bool sushu(int n) { if (n % 2 == 0) return 0;//在这题可有可无,示意可单独处理 && a > 2 for (int a = 3; a <= n/a; a += 2)//媲美sqrt,更高级的使用即时质数数组 if (n%a == 0) return 0; return 1; } void 哥德巴赫猜想表示区间() { int count = 0, i = 3, m, n; cout << "输入一个区间m-n :"; cin >> m >> n;//scanf_s if (m<6) m = 6; while (m <= n) { if (sushu(m - i) && sushu(i)) { cout << m << "=" << i << "+" << m - i << ends;//printf if (++count % 14 == 0) cout << "\n"; m += 2; i = 3; } else if (m - i > 2)i += 2; else{ cout << m << endl; m += 2; i = 3; } } }
void 哥德巴赫猜想表示区间() { int m, n, a, b, c, j, k = 0; cin >> m >> n;//缘由https://bbs.csdn.net/topics/396240545 if (m < 6)m = 6; for (; m <= n; m += 2, n -= 2) { for (a = 3; a<n / 2; a += 2, k = 0) { b = m - a; c = n - a; for (j = 3; j <= a / 2; j += 2) { if (a%j == 0){ k = 1; break; } } if (k)continue; for (j = 3; j <= b / 2; j += 2) { if (b%j == 0){ k = 1; break; } } if (k)continue; for (j = 3; j <= c / 2; j += 2) { if (c%j == 0){ k = 1; break; } } if (k){ if (b>1)printf("%d=%d+%d; ", m, a, b); continue; } if (b>1)printf("%d=%d+%d; %d=%d+%d;\n", m, a, b, n, a, c); else printf("\n"); break; } } }