HDU-1299 Diophantus of Alexandria 素因子分解
一个需要进行转化的题目。
x = (n*(n+k))/k = n*n/k + n,最后求小于等于N且是N^2的因子的数的个数。
代码如下:
#include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <map> using namespace std; int N; map<int,int>mp; map<int,int>::iterator it; int fun() { int ret = 1; for (it = mp.begin(); it != mp.end(); ++it) { ret *= (1 + 2 * it->second); } return ret; } int main() { int ca = 0, T, lim, sum; scanf("%d", &T); while (T--) { sum = 0; mp.clear(); scanf("%d", &N); lim = (int)sqrt(N*1.); for (int i = 2; i <= lim; ++i) { while (N % i == 0) { ++mp[i]; N /= i; } } printf("Scenario #%d:\n", ++ca); sum = fun(); if (N != 1) { sum *= 3; } printf("%d\n\n", sum + 1 >> 1); } return 0; }