使用C++打印出n的所有因数的查询
在给定的问题中,我们需要打印给定整数 n 的所有约数。
Input: 15 Output: 1 3 5 15 Explanation Divisors of 15 are: 1,3, 5, 15 Input: 30 Output: 1 2 3 5 15 30登录后复制
找到解决方案的方法
在给定的方法中,我们将应用埃拉托斯特尼筛法的概念,并找到n的约数。
示例
#include #define MOD 1000000007 using namespace std; vector divisors[100001]; // our vector containing number with all of its divisors void findsieve(int max) { // filling data in vector divisors till 10e5 for(int i = 1; i