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 709A Juicer

    简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...

  2. swift 2 选择头像图片

    一句话选择单个头像图片 新建ImagePickerViewController类: /* let imagePicker = ImagePickerViewController() imagePick ...

  3. unity笔录

    ----------------------------unity项目在启动splash的时候黑屏 原因不明------------------测试复制项目  用剔除法测试 笔录开始 先用原版本打包 ...

  4. 整理了一份React-Native学习指南

    原文:  http://www.w3ctech.com/topic/909 自己在学习React-Native过程中整理的一份学习指南,包含 教程.开源app和资源网站等,还在不断更新中.欢迎pull ...

  5. HDU 1847 Good Luck in CET-4 Everybody! 博弈

    题目思路: 写出SG函数(1表示先手胜,0表示先手负) 110110110110-- 发现n%3==0时,Cici胜 #include<stdio.h> #include<strin ...

  6. 如何设置linux的文件和目录的权限

    1 字符表示法 1)chmod [-R] 权限(mode)file   注:[-R]会将目录下所有权限都设置成指定的 who operator permission u(owner) +增加权限 r( ...

  7. C++实现中缀表达式转前、后缀

    #include<iostream> #include<string> #include<stack> using namespace std; bool isIn ...

  8. Spring MVC(二)

    spring mvc工作流 1A)客户端发出http请求,只要请求形式符合web.xml 文件中配置的*.action的话,就由DispatcherServlet 来处理. 1B)Dispatcher ...

  9. slf4j 之logback日志之sl4j架构【二】

    一.整体介绍 介绍: The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for v ...

  10. Excel 文件转 JSON格式对象

    将导入的如图所示格式的城乡区划代码的excel文件整理成json格式的对象储存在js文件中: var PROJECTDISTRICTDATA=[    {        "name" ...