Prime Time UVA - 10200 (打表+高精度陷阱)

探讨了Euler发现的公式n^2 + n + 41在特定区间内生成素数的比例,通过预处理素数标记,实现高效计算输入范围内素数百分比的算法。

Euler is a well-known matematician, and, among many other things, he discovered that the formulan2+n+ 41 produces a prime for 0n<40. Forn= 40, the formula produces 1681, which is 4141.Even though this formula doesn’t always produce a prime, it still produces a lot of primes. It’s knownthat forn10000000, there are 47,5% of primes produced by the formula!
So, you’ll write a program that will output how many primes does the formula output for a certaininterval.

Input

Each line of input will be given two positive integeraandbsuch that 0ab10000. You mustread until the end of the le.

Output

For each paira,bread, you must output the percentage of prime numbers produced by the formula inthis interval (anb) rounded to two decimal digits.

Sample Input

0 39
0 40
39 40

Sample Output

100.00
97.56
50.00

题意:

求输入所给范围内的数经过题目要求的变化后的数的素数百分比。

思路:
题中所给数据不大于10000,先找出1到10000之间经过变形后的素数,将
这些素数以下标的形式标记,再经过for循环找出从0到10000内的素数个数,使下面找输入数据范围内的素数个数更快速容易,最后加1e-8是因为精度问题,这是个非常非常大的坑!!这个题精度属实很高!!

代码:

#include<stdio.h>
#include<math.h>
int s[10010];
void prime()
{
    s[0]=1;
    int i,j;
    long long n;
    for(i=1; i<10000; i++)
    {
        int flag=0;
        n=i*i+i+41;
        for(j=2; j<=(int)sqrt(n); j++)
        {
            if(n%j==0)
                //flag=1;       //斜杠这些是另一种标记素数的方法 
            break;

        }
        if(j==(int)sqrt(n)+1)
                s[i]=1;
        //if(flag==0)
            //s[i]=1;
    }
    for(i=0; i<=10000; i++)
        s[i]=s[i]+s[i-1];
}
int main()
{
    int a,b,s1;
    prime();
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        s1=s[b]-s[a-1];
        printf("%.2f\n",(s1*1.0)/(b-a+1)*100+1e-8);
    }
    return 0;
}
### 关于 Adobe PrimeTime 中 UITE-529 错误的信息 在静态时序分析工具中,错误消息通常提供了关于设计约束或时钟定义方面潜在问题的具体指示。对于提到的 `UIT-529` 错误,在 PrimeTime 的上下文中可能涉及生成时钟(generated clocks)的相关配置不一致或者与时钟源路径有关的问题。 #### 可能的原因及解决方法 以下是针对该错误的一些常见原因及其对应的解决方案: 1. **生成时钟未正确定义** 如果生成时钟未能正确关联到其主时钟,则可能导致此类错误。这可以通过重新检查生成时钟命令中的 `-source` 和 `-master` 参数来验证。例如,如果生成时钟缺少有效的路径连接至主时钟,可能会触发类似的错误提示[^1]。 解决方案可以包括: - 确认生成时钟的源引脚确实存在并有效。 - 使用 `report_clocks` 命令查看当前已定义的所有时钟以及它们之间的关系。 ```tcl report_clocks -attributes all ``` 2. **延迟设置不当** 当生成时钟的上升沿或下降沿不可满足时,PrimeTime 将发出警告并将零延迟用于计算。这种情况下,需要调整相关参数以确保合理的延迟范围被指定给生成时钟。具体来说,应仔细审查是否存在过短或负数延迟的情况,并通过修改 SDC 文件修正这些问题[^1]。 3. **物理互斥组冲突** 若两个不同的生成时钟之间设置了物理互斥属性 (`set_clock_groups`) ,而实际上这些时钟间可能存在数据交互,则也可能引发类似报错。因此建议核查所有相关的 `set_clock_groups` 设置是否合理必要[^2]。 4. **SDC 脚本语法问题** 检查是否有任何拼写错误或其他形式上的失误存在于创建生成时钟及相关操作的 Tcl 脚本之中。即使是细微差别也有可能造成严重后果。比如下面的例子展示了如何正确地添加组合逻辑产生的倒相及时钟信号作为新的生成时钟实例之一[^2]: ```tcl create_generated_clock \ -add \ -name CLK_noninverted \ -combinational \ -source [get_ports CLK] \ -master CLK \ [get_pins UOR/Z] create_generated_clock \ -add \ -name CLK_inverted \ -combinational \ -invert \ -source [get_ports CLK] \ -master CLK \ [get_pins UOR/Z] ``` 最后一步则是确认所有的更改都反映到了最新的运行环境中去测试效果。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值