本文主要是介绍HDU2521(求因子个数),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2521
解题思路:
数据量不大,直接O(n)遍历,对每个数求其因子个数,找出最大的即可。
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;int f(int n)
{int s = 1;for(int i = 2 ; i * i <= n ; i ++){if(n % i == 0){int a = 0;do{n /= i;a ++;}while(n % i == 0);s = s * (a + 1);}}if(n > 1)s *= 2;return s;
}int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);int T;cin >> T;while(T--){int a , b;cin >>a >> b;int maxx = -INF;int key = 0;for(int i = a ; i <= b ; i ++){int cnt = f(i);if(cnt > maxx){maxx = cnt;key = i;}}cout << key << endl;}
}
这篇关于HDU2521(求因子个数)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!