teacher_code_c/优秀整数精.cpp

64 lines
1.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//#include <iostream>
//#include <cmath>
//#include <vector>
//using namespace std;
//
//const long long MOD = 998244353;
//const int MAX_DIGIT_SUM = 162; // 最大的位数和999999999999 的位数和为 162
//
//// 计算一个数各位数字之和
//long long digitSum(long long a) {
// long long sum = 0;
// while (a != 0) {
// sum += a % 10;
// a /= 10;
// }
// return sum;
//}
//
//// 使用埃拉托色尼筛法预计算质数表
//vector<bool> sieve(int n) {
// vector<bool> isPrime(n + 1, true);
// isPrime[0] = isPrime[1] = false;
// for (int i = 2; i * i <= n; ++i) {
// if (isPrime[i]) {
// for (int j = i * i; j <= n; j += i) {
// isPrime[j] = false;
// }
// }
// }
// return isPrime;
//}
//
//int main() {
// long long L, R;
// cin >> L >> R;
//
// // 预计算数字位和在 [0, MAX_DIGIT_SUM] 范围内的质数表
// vector<bool> primeTable = sieve(MAX_DIGIT_SUM);
//
// long long product = 1;
// bool found = false;
//
// // 显式类型转换
// long long start = static_cast<long long>(ceil(sqrt(L)));
// long long end = static_cast<long long>(floor(sqrt(R)));
//
// for (long long i = start; i <= end; i++) {
// long long square = i * i;
// if (square >= L && square <= R && primeTable[digitSum(square)]) {
// product = (product * square) % MOD;
// found = true;
// }
// }
//
// if (found) {
// cout << product << endl;
// }
// else {
// cout << 0 << endl;
// }
//
// return 0;
//}