CF_26A_AlmostPrime

A. Almost Prime
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Input contains one integer number n (1 ≤ n ≤ 3000).

Output

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

Sample test(s)
input
10
output
2
input
21
output
8


简单题目,题目描述了一类数

就是用筛法求素数,

然后利用相似的方法把要求的数打表

最后再把1到n的个数打表即可


#include <iostream>
#include <stdio.h>
using namespace std;

const int M=3005;
int pr[M];
int apr[M];
int napr[M];

int main()
{
    for(int i=2;i<M;i++)
    {
        if(pr[i])
            continue;
        for(int j=2*i;j<M;j+=i)
            pr[j]=1;
    }
    for(int i=2;i<M;i++)
    {
        if(pr[i])
            continue;
        for(int ii=i;ii<M;ii*=i)
            for(int j=i+1;j<M;j++)
            {
                if(pr[j])
                    continue;
                for(int jj=j;jj<M;jj*=j)
                {
                    if(jj*ii>M)
                        break;
                    apr[jj*ii]=1;
                }

            }
    }
    int n;
    int tot=0;
    for(int i=1;i<M;i++)
    {
        if(apr[i])
            tot++;
        napr[i]=tot;
    }
    //for(int i=1;i<M;i++)
        //cout<<napr[i]<<" ";
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",napr[n]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
修改以下代码的错误: import requests import csv import json def get_domain(ip): headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36', 'Cookie':'Q_UDID=a0087a08-8bc9-3608-ba2c-222f8a5bb22d; __guid=73887506.2650449936607309000.1676255508286.8772; cert_common=bc66e393-d403-4306-a3af-ca9e756ee279; Q=u%3D360H3407396399%26n%3D%26le%3D%26m%3DZGZ1WGWOWGWOWGWOWGWOWGWOZGpk%26qid%3D3407396399%26im%3D1_t0105d6cf9b508f72c8%26src%3Dpcw_quake%26t%3D1; __NS_Q=u%3D360H3407396399%26n%3D%26le%3D%26m%3DZGZ1WGWOWGWOWGWOWGWOWGWOZGpk%26qid%3D3407396399%26im%3D1_t0105d6cf9b508f72c8%26src%3Dpcw_quake%26t%3D1; T=s%3D61eabdeba51590da336567aacbbbeb10%26t%3D1688956103%26lm%3D%26lf%3D2%26sk%3Df74bb63ff29d85c9ac5555881d1cdefc%26mt%3D1688956103%26rc%3D%26v%3D2.0%26a%3D1; __NS_T=s%3D61eabdeba51590da336567aacbbbeb10%26t%3D1688956103%26lm%3D%26lf%3D2%26sk%3Df74bb63ff29d85c9ac5555881d1cdefc%26mt%3D1688956103%26rc%3D%26v%3D2.0%26a%3D1; Qs_lvt_344458=1688953821%2C1688972384; Qs_pv_344458=419022401534077630%2C695021803767435900; Qs_lvt_357693=1688956089%2C1689039786%2C1689125923%2C1689159866%2C1689225298; Qs_pv_357693=2550591914809554000%2C2510008180438029000%2C1154218478966065400%2C2153165497887938300%2C2883541543979267000' } url = 'https://quake.360.net/api/query/domain/' + ip res = requests.get(url=url, headers=headers, timeout=10) content = res.content.decode('utf-8') dirt = json.loads(content.text) for item in dirt['data']['domain']: print(item) def main(): with open('ips.csv', 'r') as file: ips = csv.DictReader(file) for ip in ips: get_domain(ip) if __name__ == '__main__': main()
最新发布
07-14

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值