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. 学习smail注入遇到的坑

    1.将需要被反编译的apk包解开之后,找到MainActivity,然后在OnCreate中添加需要加入注入的smail代码: Java代码: /** * 获取Android id * * @para ...

  2. 洛谷-谁拿了最多奖学金-NOIP2005提高组复赛

    题目描述 Description 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同: 1)     院士奖学金,每人8000元,期末平均成绩高于80分(>8 ...

  3. 关于oracle数据库(11)

    事务 事务是最小的工作单元,是对数据库的若干操作,增删查改(要不就都成功,要不就都失败) 在oracle数据库中,事务是默认打开的,其他数据库都需要一条语句来打开事务,默认关闭的 事务的特征 原子性. ...

  4. 获取控件id

    普通状态中JS获取控件IDdocument.getElementById('controlID'); JS获取父窗口控件IDwindow.parent.document.getElementById( ...

  5. wso2 CEP集成storm实验

    1.三台机子:192.168.225.1(manager,nimbus), 192.168.225.2(worker,supervisor), 192.168.225.3(worker,supervi ...

  6. Arpa's loud Owf and Mehrdad's evil plan

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  7. 解决getElementsByClassName兼容问题

    getElementsByClassName这个方法很常用,但是只有较新的浏览器才兼容,所以我们需要自己写个方法,解决这个问题,使它能够兼容各个浏览器. function getElementsByC ...

  8. File对象的常用方法

    File对象不仅可以表示文件,还可以表示目录,源码注释是这么说的:An abstract representation of file and directory pathnames. File类最常 ...

  9. js变量,语句

  10. HDU 3362 Fix(状压dp)

    Fix Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...