1118

优化

1.枚举到sqrt(n)2.区间有质数直接输出最大质数3.a=1 直接输出1 4.边+边与最小值比较

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define N 1000010
double minz = N;
bool f[N];
void init()
{
int i,j;
for(i = ; i <= ; i++)
{
if(!f[i])
{
for(j = i+i ; j <= N- ; j+=i)
f[j] = ;
}
}
}
double find(int k)
{
int i;
int x = sqrt(k*1.0);
double sum=;
sum+=;
for(i = ; i <= x ; i++)
{
if(k%i==)
{
sum+=k/i+i;
}
if(sum/k>minz) break;
}
return sum/k;
}
int main()
{
int i,a,b;
init();
cin>>a>>b;
int ans=-;
if(a==)
{
printf("1\n");
return ;
}
for(i = a ; i <= b ; i++)
{
if(!f[i]) ans = i;
}
if(ans!=-)
{
printf("%d\n",ans);
return ;
}
for(i = a; i <= b ; i++)
{
double s = find(i);
if(s<minz)
{
ans = i;
minz = s;
}
}
printf("%d\n",ans);
return ;
}

URAL1118. Nontrivial Numbers的更多相关文章

  1. ural 1118. Nontrivial Numbers

    1118. Nontrivial Numbers Time limit: 2.0 secondMemory limit: 64 MB Specialists of SKB Kontur have de ...

  2. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  3. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  4. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  5. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  6. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  7. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  8. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  9. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

随机推荐

  1. 7-Highcharts曲线图之分辨带

    <!DOCTYPE> <html lang='en'> <head> <title>7-Highcharts曲线图之分辨带</title> ...

  2. Cross Validation done wrong

    Cross Validation done wrong Cross validation is an essential tool in statistical learning 1 to estim ...

  3. C语言中inline的用法

    C语言里面的内联函数(inline)与宏定义(#define)探讨 先简明扼要,说下关键: 1.内联函数在可读性方面与函数是相同的,而在编译时是将函数直接嵌入调用程序的主体,省去了调用/返回指令,这样 ...

  4. 利用GBDT模型构造新特征具体方法

    利用GBDT模型构造新特征具体方法 数据挖掘入门与实战  公众号: datadw   实际问题中,可直接用于机器学**模型的特征往往并不多.能否从"混乱"的原始log中挖掘到有用的 ...

  5. 使用Varnish代替Squid做网站缓存加速器的详细解决方案----转载

    [文章作者:张宴 本文版本:v1.2 最后修改:2008.01.02 转载请注明出处:http://blog.s135.com] 我曾经写过一篇文章──<初步试用Squid的替代产品──Varn ...

  6. URAL 1517 Freedom of Choice(后缀数组,最长公共字串)

    题目 输出最长公共字串 #define maxn 200010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int cmp(int *r,int a,int b, ...

  7. POJ 1151 Atlantis(经典的线段树扫描线,求矩阵面积并)

    求矩阵的面积并 采用的是区间更新 #include <iostream> #include <stdio.h> #include <string.h> #inclu ...

  8. 在DECIMAL(m,n)的设置中,整数的位数不能大于(m-n)

    关于DB2的DECIMAL类型 创建表的时用的是DECIMAL(13,2),我认为它为13个整数位数+2为有效数字,因为在打印银行交易的FORM时遇到了难题.输出和建表的长度不一样,我们以为它会打印出 ...

  9. 机器学习之多变量线性回归(Linear Regression with multiple variables)

    1. Multiple features(多维特征) 在机器学习之单变量线性回归(Linear Regression with One Variable)我们提到过的线性回归中,我们只有一个单一特征量 ...

  10. Android核心分析之二十一Android应用框架之AndroidApplication

    Android Application Android提供给开发程序员的概念空间中Application只是一个松散的表征概念,没有多少实质上的表征.在Android实际空间中看不到实际意义上的应用程 ...