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. [SOJ] 无路可逃?

    Description 唐僧被妖怪关在迷宫中.孙悟空好不容易找到一张迷宫地图,并通过一个魔法门来到来到迷宫某个位置.假设迷宫是一个n*m的矩阵,它有两种地形,1表示平地,0表示沼泽,孙悟空只能停留在平 ...

  2. 《Intel汇编第5版》 汇编拷贝字符串

    一.字符串定义 二.dup指令 三.调用Writestring过程 四.代码以及效果 TITLE String Copy INCLUDE Irvine32.inc includelib Irvine3 ...

  3. DEBUG 调试

    1.Step Into (also F5) 跳入 2.Step Over (also F6) 跳过 3.Step Return (also F7) 执行完当前method,然后return跳出此met ...

  4. Chapter 16_5 单一方法

    当一个对象只有一个方法时,可以不用创建接口table,但是要将这个单独的方法作为对象来返回.可以参考迭代器那一节,是如何构造一个迭代器函数,那个函数将状态保存为closure. 一个具有状态的迭代器是 ...

  5. Flashbuilder 破解方式 4.6 +4.7(网络资源整理)

    Fb4.6 破解方式 安装完成后在安装目录下依次修改下列3个文件: (1).eclipse\plugins\com.adobe.flexbuilder.project_4.6.0.328916\MET ...

  6. EFI安装Win7

    安装系统之前电脑里最好没有其他系统,安装过程中电脑需重启多次,其他系统会引导电脑开机,无法完成WIN7安装. 一.制作安装分区 1.首先在移动硬盘(U盘)准备一个FAT32分区 一定要FAT32分区, ...

  7. python 基础学习3-函数

    1. 函数参数-默认参数 python函数也可以跟C语言一样,在函数的形参中设定默认值. >>> def test(flag, port = 8080) ... print port ...

  8. ubuntu 安装python mysql模块

    Installation Starting with a vanilla Lucid install , install pip and upgrade to the latest version: ...

  9. L2-002. 链表去重

    L2-002. 链表去重 题目链接:https://www.patest.cn/contests/gplt/L2-002 这题因为结点地址只有四位数,所以可以直接开一个10000的数组模拟内存就好了. ...

  10. POJ 3264 RMQ裸题

    POJ 3264 题意:n个数,问a[i]与a[j]间最大值与最小值之差. 总结:看了博客,记下了模板,但有些地方还是不太理解. #include<iostream> #include&l ...