TLE求助

P1075 [NOIP2012 普及组] 质因数分解

其实不用判断是不是质数的。题目说N是两个质数的乘积,所以直接暴力枚举因数就好了。
by Jellychen @ 2024-02-08 11:45:19


先找质数然后暴力 ```cpp #include<iostream> #include<bitset> #include<algorithm> #include<vector> using namespace std; auto getPrimeList() { const unsigned int maxNum = 1000000; bitset<maxNum> compositeTagList; vector<unsigned int> primeList = {}; for (unsigned int i = 2; i < maxNum; i += 1) { if (compositeTagList[i] == false) { for (unsigned long int j = i * 2; j < maxNum; j += i) { if (compositeTagList[j] == false) compositeTagList[j] = true; } primeList.push_back(i); } } return primeList; } auto primeList = getPrimeList(); int main() { unsigned int n; cin >> n; for (const unsigned int &x: primeList) { if (n % x == 0) { cout << n / x; break; } } return 0; } ```
by 145a @ 2024-03-01 09:04:01


你知道什么叫平方根吧?这题可以用上
by 13860121259AaBb @ 2024-03-03 20:15:51


|