UVA 294 - Divisors 因子个数
Mathematicians love all sorts of odd properties of numbers. For instance, they consider 945 to be an interesting number, since it is the first odd number for which the sum of its divisors is larger than the number itself.
To help them search for interesting numbers, you are to write a program that scans a range of numbers and determines the number that has the largest number of divisors in the range. Unfortunately, the size of the numbers, and the size of the range is such that a too simple-minded approach may take too much time to run. So make sure that your algorithm is clever enough to cope with the largest possible range in just a few seconds.
The first line of input specifies the number N of ranges, and each of the N following lines contains a range, consisting of a lower bound Land an upper bound U, where L and U are included in the range. L and U are chosen such that and
.
For each range, find the number P which has the largest number of divisors (if several numbers tie for first place, select the lowest), and the number of positive divisors D of P (where P is included as a divisor). Print the text 'Between L and H, P has a maximum of Ddivisors.', where L, H, P, and D are the numbers as defined above.
3
1 10
1000 1000
999999900 1000000000
Between 1 and 10, 6 has a maximum of 4 divisors.
Between 1000 and 1000, 1000 has a maximum of 16 divisors.
Between 999999900 and 1000000000, 999999924 has a maximum of 192 divisors. 题意:给你 a,b,让你找出 a,b之间因子最多的数是多少 b-a《=1000 我们枚举就好了
//meek
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include<map>
#include<queue>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair const int N=;
const ll INF = 1ll<<;
const int inf = ;
const int MOD = ; ll cal(ll x) {
ll hav = ;
for(ll i = ; i*i <= x; i++) {
if(x % i == ) hav ++;
if(x % i == && x / i != i) hav++;
}
return hav;
}
int main() {
int T;
ll a,b,ans,tmp;
scanf("%d",&T);
while(T--) {
ans = -;
scanf("%lld%lld",&a,&b);
for(ll i = a; i <= b; i++) {
ll temp = cal( i );
if(temp > ans) {
ans = temp;
tmp = i;
}
}
printf("Between %lld and %lld, %lld has a maximum of %lld divisors.\n",a,b,tmp,ans);
}
return ;
}
代码
UVA 294 - Divisors 因子个数的更多相关文章
- UVA - 294 Divisors【数论/区间内约数最多的数的约数个数】
Mathematicians love all sorts of odd properties of numbers. For instance, they consider to be an int ...
- UVa 294 (因数的个数) Divisors
题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...
- UVA - 294 Divisors (约数)(数论)
题意:输入两个整数L,U(1<=L<=U<=109,U-L<=10000),统计区间[L,U]的整数中哪一个的正约数最多.如果有多个,输出最小值. 分析: 1.求一个数的约数, ...
- UVa 294 - Divisors 解题报告 c语言实现 素数筛法
1.题目大意: 输入两个整数L.H其中($1≤L≤H≤10^9,H−L≤10000$),统计[L,H]区间上正约数最多的那个数P(如有多个,取最小值)以及P的正约数的个数D. 2.原理: 对于任意的一 ...
- Uva 294 Divisors(唯一分解定理)
题意:求区间内正约数最大的数. 原理:唯一分解定义(又称算术基本定理),定义如下: 任何一个大于1的自然数 ,都可以唯一分解成有限个质数的乘积 ,这里 均为质数,其诸指数 是正整数.这样的分解称 ...
- UVA 294 294 - Divisors (数论)
UVA 294 - Divisors 题目链接 题意:求一个区间内,因子最多的数字. 思路:因为区间保证最多1W个数字,因子能够遍历区间.然后利用事先筛出的素数求出质因子,之后因子个数为全部(质因子的 ...
- Divisors (求解组合数因子个数)【唯一分解定理】
Divisors 题目链接(点击) Your task in this problem is to determine the number of divisors of Cnk. Just for ...
- Almost All Divisors(求因子个数及思维)
---恢复内容开始--- We guessed some integer number xx. You are given a list of almost all its divisors. Alm ...
- POJ 2992 Divisors (求因子个数)
题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...
随机推荐
- Blender插件之操作器(Operator)实战
前言 在Blender中, 操作器(Operator)是它的核心. 用户通过各种操作器来创建和操作场景中的物体. 操作器对象继承自 class bpy.types.Operator(bpy_struc ...
- 关于一些UI的插件(杂)
1.时间插件 //日期框 $('.date-picker').datepicker(); 2.checkbox 保存checkbox的值 // 组装选择的标签 var check = $(" ...
- DataTable转Json就是这么简单(Json.Net DLL (Newtonsoft))
之前JSON转DataTable可以见我之前的随笔 链接Json转换成DataTable 之前没有用过DataTable,之后随着需求的叠加发现需要将DataTable转换成Json.因为之前都是用的 ...
- JavaScript的switch循环
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...
- 08.十分钟学会JSP传统标签编程
一.认识标签 1,说明:传统标签编程在开发中基本用不到,学习标签编程主要还是为了完善知识体系. 2,标签的主要作用:移除或减少jsp中的java代码 3,标签的主要组成部分及运行原理 4,简单标签示例 ...
- 计算机二级考试Access教程
本教程对编程语言各种要点进行详细的讲解介绍,从基础知识到实用技术功能,内容涵盖了从数组,类等基本概念到多态.模板等高级概念.教程本着实用的原则,每一小节都结合了可以笔试.面试的常见程序实例,以便从第一 ...
- 【转】【Oracle 集群】Linux下Oracle RAC集群搭建之基本测试与使用(九)
原文地址:http://www.cnblogs.com/baiboy/p/orc9.html 阅读目录 目录 检查RAC状态 检查创建的数据库 全部参考文献 相关文章 Oracle 11G RAC ...
- PHP中each与list用法分析
1.each的用法 先看API array each ( array &$array ) api里是这么描述的:each — 返回数组中当前的键/值对并将数组指针向前移动一步 我们先来看看返回 ...
- android的listview的addheaderView总是出现空指针的错误
android的listview的addheaderView总是出现空指针的错误, 网上的处理方法如下: // This doesn't work... nullPointerException Li ...
- 一、简介 ELO商户类别推荐有助于了解客户忠诚度
Elo Merchant Category Recommendation Help understand customer loyalty (ELO商户类别推荐有助于了解客户忠诚度) 竞赛描述: 想象 ...