UVA 10200 Prime Time 暴力水题

一个简单的暴力水题,只是输出方式让人无语。。。

#include <stdio.h>
#include <string.h>
int prime(int n)
{
    int i;
    for(i=2;i*i<=n;i++)
    {
        if((n%i)==0)
            return 0;
    }
    return 1;
}
int main()
{
    int num[10010];
    int i;
    int a,b;
    int sum;
    memset(num,0,sizeof(num));
    for(i=0;i<=10005;i++)
        num[i]=prime(i*i+i+41);
    while(scanf("%d%d",&a,&b)!=-1)
    {
        sum=0;
        for(i=a;i<=b;i++)
            sum+=num[i];
        printf("%.2f\n",sum*1.0/(b-a+1)*100+1e-8);      //一定要加这个1e-8,不然就是判错,我也不知道为什么,有谁知道的话请务必告诉我
    }
    return 0;
}
时间: 2024-08-09 21:53:53

UVA 10200 Prime Time 暴力水题的相关文章

UVA 10200 Prime Time 水

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1141 题意:判断区间[a,b]的f(i)是否为素数,f(i)=i*i+i+40: 思路:打个表,然后注意精度: #include<bits/stdc++.h> using namespace std; #define ll long long #define esp

UVA 10200 Prime Time(简单素数判定预处理)

Euler is a well-known matematician, and, among many other things, he discovered that the formula n 2 + n + 41 produces a prime for 0 ≤ n < 40. For n = 40, the formula produces 1681, which is 41 ∗ 41. Even though this formula doesn’t always produce a

UVA 10200 Prime Time

题意:给你两个数a,b,求[a,b]内有多少个数满足f(n)=n*n+n+41是素数. 题解:预处理除前缀和,直接求 #include<cstring> #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<stack> #include<vector> #define N 10010 using namespace

hdu 3687 10 杭州 现场 H - National Day Parade 暴力水题

H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3687 Appoint description:  System Crawler  (2014-11-08) Description There are n×n students preparing for the National Day

UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)

两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio> #include <cctype> #include <string> #include <

UVA 10200 记忆打表,素数筛,浮点误差

UVA 10200 区间预处理,浮点误差 W - Prime Time Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 10200 Description 题意:测试找素数函数f(n)=n^2+n+41在区间n<-[a,b]时,找到素数的成功率. 思路:区间的素数个数,打表预处理即可.输出答案时四舍五入,需注意浮点误差,四舍五入时加上EPS. #

UVA - 524 Prime Ring Problem(dfs回溯法)

UVA - 524 Prime Ring Problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers  into each circle separately, and the sum of number

HDU-2504-又见GCD(Java强行暴力水过!)

又见GCD Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12371    Accepted Submission(s): 5257 Problem Description 有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b.若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c. Input 第一行输入一个n

[2016-02-19][UVA][524][Prime Ring Problem]

UVA - 524 Prime Ring Problem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers  into each circle separately, and the