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. yum install 与 yum groupinstall 的区别

    原文:http://blog.51yip.com/linux/1171.html yum 提供二种安装软件的方式 1,yum install 它安装单个软件,以及这个软件的依赖关系 2,yum gro ...

  2. 如何用 Parse 和 Swift 搭建一个像 Instagram 那样的应用?(3)

    [编者按]本篇文章作者是 Reinder de Vries,既是一名企业家,也是优秀的程序员,发表多篇应用程序的博客.本篇文章中,作者主要介绍了如何基于 Parse 特点,打造一款类似 Instagr ...

  3. C#实现文件增量备份

    最近将客户的一个ASP网站部署到了公司的机房云服务器上,该ASP网站的文件总容量已有将近4GB. 虽然现在硬盘容量很大,但每天一次完整备份的话,那占用的硬盘空间会急剧上升,考虑一个更优的备份方案就是每 ...

  4. 数据库(.udl)简单测试连接

    当我们烦于打开数据库进行连接的时候,我们可以用udl进行测试连接,并可以获得连接字符串. 1.新建一个txt文件,然后将后缀改成udl保存. 2.双击打开udl文件. 3.进行数据库连接测试. 4.用 ...

  5. POJ 1947 Rebuilding Roads(树形DP)

    题目链接 题意 : 给你一棵树,问你至少断掉几条边能够得到有p个点的子树. 思路 : dp[i][j]代表的是以i为根的子树有j个节点.dp[u][i] = dp[u][j]+dp[son][i-j] ...

  6. 关于解压覆盖IIS文件后,新的文件不具备权限导致DMS系统无法正常运行

     向DMS的服务器端站点bin目录覆盖任何补丁文件,请注意:Web站点的bin目录中的文件,IIS的服务进程(Windows2003以上,都是对应Network Services账户)必须对这些文件具 ...

  7. Struts2 Convention插件的使用(3)方法前的@Action注解

    package com.hyy.action; import org.apache.struts2.convention.annotation.Action; import com.opensymph ...

  8. 15.RDD 创建内幕解析

    第15课:RDD创建内幕 RDD的创建方式 Spark应用程序运行过程中,第一个RDD代表了Spark应用程序输入数据的来源,之后通过Trasformation来对RDD进行各种算子的转换,来实现具体 ...

  9. AC自动机总结

    AC自动机的模板 void buildAC() { while(!q.empty()) q.pop(); q.push(); while(!q.empty()) { int x=q.front();q ...

  10. 与Wii控制手柄通信的托管代码库(转)

    2009-01-16 翻译 HID Human Input Device     人工输入设备 Wii Fit Balance Board       平衡板 IR                   ...