博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
区间内约数最多的书的约数个数
阅读量:3952 次
发布时间:2019-05-24

本文共 2177 字,大约阅读时间需要 7 分钟。

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. Input 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 L and an upper bound U, where L and U are included in the range. L and U are chosen such that 1 ≤ L ≤ U ≤ 1000000000 and 0 ≤ U − L ≤ 10000. Output 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 D divisors.’, where L, H, P, and D are the numbers as defined above. Sample Input

3

1 10

1000 1000

999999900 1000000000

Sample Output

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.

【方法】

枚举即可

#include 
using namespace std;typedef long long ll;ll l,r;ll solve(ll n){ ll ans=0; for(ll i=1;i*i<=n;i++) { if(n%i==0) ans++; if(n%i==0&&n/i!=i) ans++; } return ans;}int main(){ ios::sync_with_stdio(false); int t; cin>>t; while(t--) { cin>>l>>r; ll x,ans=0; for(ll i=l;i<=r;i++) { ll t=solve(i); if(t>ans) { ans=t; x=i; } } cout<<"Between "<
<<" and "<
<<", "<
<<" has a maximum of "<
<<" divisors."<

 

转载地址:http://ovyzi.baihongyu.com/

你可能感兴趣的文章
MFC CListBox的使用
查看>>
VS2008向MFC 对话框 添加托盘图标(显示和消失)
查看>>
redhat中vsftp开机自启动
查看>>
MySQL存储过程,生成大量数据
查看>>
查询字段值出现多次的字段值
查看>>
SQL Server表存在则进行查重 SQL语句
查看>>
redhat 9 下sqlite 3的安装及编程
查看>>
两个同步表的字段复制.Oracle.
查看>>
windows MySQL 报“Got a packet bigger than 'max_allowed_packet' bytes”错误,解决过程.
查看>>
在Redhat9下静态编译glib库.
查看>>
CImg库编译使用.
查看>>
SQL Server循环执行动态SQL语句.
查看>>
ubuntu10.4网卡名由eth0改为eth4,导致获得不了IP地址.解决方法.
查看>>
CheckPoint关键词做字段名使用.
查看>>
Qt QSplitte分割器使用(用户手动改变窗口大小)
查看>>
Qt动态加载动态库
查看>>
java8新特性
查看>>
git clone时RPC failed; curl 18 transfer closed with outstanding read data remaining
查看>>
Java8内存模型—永久代(PermGen)和元空间(Metaspace)
查看>>
maven中jar、war、pom的区别
查看>>