1118. Nontrivial Numbers

Time limit: 2.0 second
Memory limit: 64 MB
Specialists of SKB Kontur have developed a unique cryptographic algorithm for needs of information protection while transmitting data over the Internet. The main advantage of the algorithm is that you needn't use big numbers as keys; you may easily do with natural numbers not exceeding a million. However, in order to strengthen endurance of the cryptographic system it is recommended to use special numbers - those that psychologically seem least "natural". We introduce a notion oftriviality in order to define and emphasize those numbers.
Triviality of a natural number N is the ratio of the sum of all its proper divisors to the number itself. Thus, for example, triviality of the natural number 10 is equal to 0.8 = (1 + 2 + 5) / 10 and triviality of the number 20 is equal to 1.1 = (1 + 2 + 4 + 5 + 10) / 20. Recall that a proper divisor of a natural number is the divisor that is strictly less than the number.
Thus, it is recommended to use as nontrivial numbers as possible in the cryptographic protection system of SKB Kontur. You are to write a program that will find the less trivial number in a given range.

Input

The only line contains two integers I and J, 1 ≤ I ≤ J ≤ 106, separated with a space.

Output

Output the only integer N satisfying the following conditions:
  1. I ≤ N ≤ J;
  2. N is the least trivial number among the ones that obey the first condition.

Sample

input output
24 28
25

题意:

“SKB-Kontur”的专家们开发了一种独特的密码算法以满足在互联网上传送数据时的信息保密需要。这种算法的最大好处是,您不需要使用大数字作为密码——您可以方便地用小于一百万的自然数作为密码。但是,为了加强密码系统的安全性,推荐您使用特殊数字——那些心理上认为最不“自然”的数字。我们引入“Triviality”这个概念定义和强调那些数字。

一个自然数N的“Triviality”被定义它所有的Proper约数之和与它本身的比值。例如,自然数10的“Triviality”是0.8=(1+2+5)/10,自然数20的“Triviality”是1.1=(1+2+4+5+10)/20。注意一个自然数的Proper约数是指这个数的所有约数中严格地小于这个数本身的那些约数。

正因为如此,在“SKB-Kontur”密码安全系统中推荐尽可能使用Non-Trivial数字。你的任务是写一个程序,在给定的范围内找出“Triviality”值最小的数字。

思路:其实就是暴力,只不过加了一些优化;

代码:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string> using namespace std; int judge(int m)
{
int p=;
int k=sqrt((double)m);
for(int i=;i<=k;i++){
if(m%i==){
if(i==k &&k*k==m)p+= i;
else p+=i+m/i;
}
}
return p;
} int main()
{
int a,b;
cin>>a>>b;
if(a==){
printf("1\n");
return ;
}
double minx=0x7ffff;
double p=;
int t;
for(int i=b;i>=a;i--){
p=judge(i);
if(p==1.0){
t=i;
break;
}
if(minx>p/i){
minx=p/i;
t=i;
}
}
printf("%d\n",t);
return ;
}

ural 1118. Nontrivial Numbers的更多相关文章

  1. 递推DP URAL 1586 Threeprime Numbers

    题目传送门 /* 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 所以,dp[i ...

  2. 递推DP URAL 1009 K-based Numbers

    题目传送门 题意:n位数,k进制,求个数分析:dp[i][j] 表示i位数,当前数字为j的个数:若j==0,不加dp[i-1][0]; 代码1: #include <cstdio> #in ...

  3. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  4. ural 1150. Page Numbers

    1150. Page Numbers Time limit: 1.0 secondMemory limit: 64 MB John Smith has decided to number the pa ...

  5. URAL 2031. Overturned Numbers (枚举)

    2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the In ...

  6. URAL 1002 Phone Numbers(KMP+最短路orDP)

    In the present world you frequently meet a lot of call numbers and they are going to be longer and l ...

  7. URAL1118. Nontrivial Numbers

    1118 优化 1.枚举到sqrt(n)2.区间有质数直接输出最大质数3.a=1 直接输出1 4.边+边与最小值比较 #include <iostream> #include<cst ...

  8. URAL 1012 K-based Numbers. Version 2(DP+高精度)

    题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...

  9. ural 1013. K-based Numbers. Version 3(动态规划)

    1013. K-based Numbers. Version 3 Let’s consider K-based numbers, containing exactly N digits. We def ...

随机推荐

  1. CodeForces 687B Remainders Game

    数论. 如果$x$不唯一,假设存在两个解,较大的为${x_1}$,较小的为${x_2}$. 那么, $\left\{ {\begin{array}{*{20}{c}}{{x_1}\% {c_i} = ...

  2. [HMLY]4.CocoaPods详解----制作

    作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory/article/details/20067595 转载请注明出处   学会使用别人的pods依赖库后,你一 ...

  3. C++类的实例化的两种方法

    C++ 类的实例化有两种方法: 直接定义对象: 先定义一个类:   class A { public: A(); virtual ~A(); ... ... };   类实现略. 用的时候: A a; ...

  4. [UWP小白日记-2]SQLite数据库DOME

    数据库说简单点就是增删改查,但是对新手来说也是要爆肝的.作为一个新手爆肝无数次啊, 血的教训啊现在UWP的教程又少,说多了都是泪.留下来免得以后又爆肝.还有:一定要写注释!一定要写注释!一定要写注释! ...

  5. Android 6.0之权限管理

    安卓6.0的权限体系分为非敏感权限和敏感权限,非敏感权限默认获取,可以手动关闭. 敏感权限必须由app在运行时动态申请.而存储读写空间权限是一个敏感权限,不是一个“很正常的必须权限”. 安卓并不是想要 ...

  6. 容易忘记的几个Linux命令

    #查看文件或者目录的属性ls -ld filenamels -ld directory #vi编辑器输入:.,$d #清除全部内容 #修改管理员.用户密码passwd user #("use ...

  7. VMware下安装CentOS6.5

    一.工具 1.VMware-workstation-full-12.5.0-4352439.exe 2.CentOS-6.5-x86_64-minimal.iso 二.安装VMware虚拟机 1.选择 ...

  8. 微信小程序开发详解——小程序,大颠覆!

    微信小程序开发 联系 苏念 188.1414.7927  微信小程序系统开发 微信新功能开发 小程序开发 小程序怎么开发 app小程序开发 简化小程序开发 微信小程序定制 小程序制作 开发微信小程序  ...

  9. css的三大特性

    1.继承性 作用:子元素可以继承父元素的样式text-,font-,line-这些元素开头的都可以继承,以及color属性特殊性: ①. a标签的颜色不能继承,必须对a标签本身进行设置 ②. h标签的 ...

  10. 基于jQuery弹性展开收缩菜单插件gooey.js

    首先 引入css <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel ...