HDU-1299 Diophantus of Alexandria 素因子分解
生活随笔
收集整理的這篇文章主要介紹了
HDU-1299 Diophantus of Alexandria 素因子分解
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一個需要進行轉(zhuǎn)化的題目。
x = (n*(n+k))/k = n*n/k + n,最后求小于等于N且是N^2的因子的數(shù)的個數(shù)。
代碼如下:
#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; }轉(zhuǎn)載于:https://www.cnblogs.com/Lyush/archive/2012/07/25/2608030.html
總結(jié)
以上是生活随笔為你收集整理的HDU-1299 Diophantus of Alexandria 素因子分解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android sqlite SQLit
- 下一篇: jQuery仿淘宝商城天猫鼠标移动过去,