数学——Almost Prime

Almost Prime

题面翻译

题目描述

一个数如果恰好有两个不同质因子,那它被叫做几乎是质数的数。例如:6,18,24就是几乎是质数的数,而4,8,9,42不是,请你找出 1 1 1 n n n 中几乎是质数的数有多少个。

输入格式

输入仅包含一个整数 n n n 1 ≤ n ≤ 3000 1\leq n\leq3000 1n3000)。

输出格式

输出 1 1 1 n n n 中几乎是质数的数的数量。

Translated by Khassar

题目描述

A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and $ n $ , inclusive.

输入格式

Input contains one integer number $ n $ ( $ 1<=n<=3000 $ ).

输出格式

Output the amount of almost prime numbers between 1 and $ n $ , inclusive.

样例 #1

样例输入 #1

10

样例输出 #1

2

样例 #2

样例输入 #2

21

样例输出 #2

8

思路

我们可以用类似筛选法的思路来解决,只要同一个数被加了两次就满足题意。

代码

#include<iostream>
#include<algorithm>

using namespace std;

const int N = 3e5+10;

int b[N];
int n;
int ans;

int main(){
    cin>>n;
    
    b[1]=1;
    for(int i=2;i<=n;i++){
        if(!b[i]){
            for(int j=2;i*j<=n;j++){
                b[i*j]++;
            }
        }
    }
    
    for(int i=1;i<=n;i++){
        if(b[i]==2){
            ans++;        
        }
    }
    
    cout<<ans;
    
    return 0;
    
}

FIFO的almost full状态是指FIFO缓冲区接近满的状态。在FIFO设计中,为了提前判断FIFO是否即将满,通常会引入almost_full信号。引用\[2\]中提到的方法二,通过将FIFO的Empty和Almost_empty信号与读使能配合使用,可以准确地判断FIFO的空满状态,并提前决定是否启动读操作。而almost_full信号则用于指示FIFO是否接近满的状态,当FIFO的填充值接近预定的全值时,almost_full信号会被置位。这样,系统可以根据almost_full信号来做出相应的处理,例如提前进行据读取或者进行其他操作,以避免FIFO溢出的情况发生。因此,FIFO的almost full状态是为了提前预警FIFO即将满的情况,以便系统能够及时做出相应的处理。 #### 引用[.reference_title] - *1* [异步FIFO学习](https://blog.csdn.net/zgezi/article/details/107040231)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [FIFO读写时序理解——almost_empty、almost_full](https://blog.csdn.net/weixin_45793915/article/details/127026845)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

green qwq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值