ural 1118. Nontrivial Numbers
1118. Nontrivial Numbers
Memory limit: 64 MB
Input
Output
- I ≤ N ≤ J;
- 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的更多相关文章
- 递推DP URAL 1586 Threeprime Numbers
题目传送门 /* 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 所以,dp[i ...
- 递推DP URAL 1009 K-based Numbers
题目传送门 题意:n位数,k进制,求个数分析:dp[i][j] 表示i位数,当前数字为j的个数:若j==0,不加dp[i-1][0]; 代码1: #include <cstdio> #in ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 1150. Page Numbers
1150. Page Numbers Time limit: 1.0 secondMemory limit: 64 MB John Smith has decided to number the pa ...
- URAL 2031. Overturned Numbers (枚举)
2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the In ...
- 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 ...
- URAL1118. Nontrivial Numbers
1118 优化 1.枚举到sqrt(n)2.区间有质数直接输出最大质数3.a=1 直接输出1 4.边+边与最小值比较 #include <iostream> #include<cst ...
- URAL 1012 K-based Numbers. Version 2(DP+高精度)
题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...
- 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 ...
随机推荐
- [SOJ] 导游
Description Mr. G. 在孟加拉国的一家旅游公司工作.他当前的任务是带一些游客去一些遥远的城市.和所有国家一样,一些城市之间有双向道路.每对相邻城市之间都有一条公交路线,每条路线都规定了 ...
- [河南省ACM省赛-第四届] 序号互换 (nyoj 303)
相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题六 最小生成树 POJ 1251 Jungle Roads
题意: 有n个点 每个点上有一些道路 求最小生成树 解释下输入格式 A n v1 w1 v2 w2 A点上有n条边 A到v1权值是w1 A到v2权值是w2 思路: 字符串处理之后跑kruskal求最小 ...
- 在spring拦截器中response输出html标签到页面
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object ...
- HDU 4262 Juggler
点我看题 初步想法是模拟,找到下一个位置并记录操作数,O(n^2)肯定会超时. 那么进行优化,会发现到下一位置的操作数就是两个位置之间存在的数的个数,于是就变成了计数问题. 不难想到用树状数组或线段树 ...
- Oracle跨库访问数据表-DBLINK
1:创建DBLINK(USING后面的连接字符串就是要访问的那个数据库的连接字符串) CREATE DATABASE LINK linkName CONNECT TO userName IDENTIF ...
- 读取和存储文本文件,UTF-8和GB2312通用的函数
'------------------------------------------------- '函数名称:ReadTextFile '作用:利用AdoDb.Stream对象来读取UTF-8格式 ...
- php中函数 vsprintf() 和 var_export()
把格式化字符串写入变量中: <?php $number = 9; $str = "Beijing"; $txt = vsprintf("There are %u m ...
- es6--(三)set和map数据结构
1.Set和WeakSet Set与数组相似,但是Set结构的成员必须是唯一的. WeakSet与对象类型,但是WeakSet结构的成员只能是对象 Set结构的实例属性和方法 属性: Set.prot ...
- C# .NETWEB开发6大内置对象
ASP.NET 内置对象包括 1.Response 2.Request 3.Server 4.Application 5.Session 6.Cookie 1 Request对象主要是让 ...