C. Bear and Prime Numbers(线性筛素数)

避开这5个坑!STC8H DMA串口通信的实战避坑指南(115200波特率实测) 本文深入解析了STC8H单片机利用DMA实现稳定全双工串口通信的实战要点。针对115200高波特率场景,详细拆解了DMA-UART架构、关键寄存器配置、时钟精度计算、缓冲区管理及中断协同等核心环节,并提供了具体的避坑指南和调试方法,帮助开发者构建高效可靠的通信链路。 阅读详情
题目链接:C. Bear and Prime Numbers
题意:

给出一个有n个数的序列和m次查询,m次查询给出一个区间,求区间中素数的函数值f(p)之和。f(p)表示能序列中能整除p的元素个数。

思路:

线性筛出素数,在筛选素数的同时,处理f(p)。采用线性筛素数就能得出每个素数是序列中哪几个数字的倍数。一举两得,再使用前缀和处理一下。得到答案。

代码:

#include<iostream>
#include<string>
#include<cstring> 
using namespace std;
const int N=10000010;
int n,m,l,r,prime[N],f[N],s[N];
void Init(){
    int i,j;
    memset(prime,0,sizeof(prime));
    memset(f,0,sizeof(f));
    memset(s,0,sizeof(s));
    cin>>n;
    for(i=0;i<n;++i){
        int tmp;
        cin>>tmp;
        s[tmp]++;
    }
    //打表 处理f(p)
    for(i=2;i<N;++i){
        if(prime[i])continue;
        for(j=i;j<N;j+=i){
            //s[j]如果不为0 说明序列中有元素值为j,并且j还是素数i的倍数,f(i)+=s[j],就能得到f(p);
            if(s[j])f[i]+=s[j];
            prime[j]=1;
        }
    } 
    //前缀和处理
    for(i=2;i<=N;++i)f[i]+=f[i-1]; 
}
void solve(){
    cin>>m;
    for(int i=1;i<=m;++i){
        cin>>l>>r;
        if(l>N)l=N;
        if(r>N)r=N;
        cout<<f[r]-f[l-1]<<endl;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    Init();
    solve();    
    return 0;
 } 
Android 13.0 双屏时触摸失效问题排查与修复 摘要:本文记录了RK3588 Android12开发板上主屏触摸失效问题的排查与解决过程。通过分析发现,USB触摸设备被错误关联到辅屏(displayId=3)而非主屏(displayId=0)。解决方案是修改TouchInputMapper.cpp,强制触摸设备使用INTERNAL viewport(主屏),并保持设备在viewport不活跃时仍启用。该修改涉及约40行代码,有效解决了多显示器环境下触摸设备错误映射的问题,同时提供了详细的调试方法和注意事项。 阅读详情

相关推荐

UE4游戏开发:GameInstance与GameMode的实战应用与避坑指南

本文深入解析了UE4中GameInstance与GameMode的核心差异与实战应用。GameInstance作为贯穿游戏进程的全局单例,负责跨关卡数据持久化与系统管理;而GameMode则定义特定关卡内的游戏规则与逻辑,随关卡加载销毁。文章通过数据存储、动态模式切换及网络游戏等场景,提供了清晰的应用指南与常见避坑方案,帮助开发者构建更健壮的UE4游戏架构。

kubernetes8ctl的博客 230

codeforces-385C Bear and Prime Numbers(素数筛选法+维护前缀和)

题目链接:点击打开链接 题意:求在区间[a,b]内所有素数的f(x)之和,f(x)为在数组中能整除x的数的个数。例如长度为6的数组{5,5,7,10,14,15},给出区间[2,11],则f(2)=2,f(3)=1,f(5)=4,f(7)=2,f(11)=0.           ∑[f(x)]=f(2)+f(3)+f(5)+f(7)+f(11)=9. 分析:先用数组b[i]记录输入

CHeck_Check_check的博客 634

把对讲门铃(控制底楼铁门)接入米家服务器

今天讲个跟SDR或者无人机无关的东西,技术含量不高,但是方便了我的生活。 现在家门有智能锁,汽车也可以远程解锁发动,NFC门禁也可以用某些手机复制,唯独楼下的铁门,必须用老式对讲门铃控制。 也就是说其它钥匙都可以不带,就剩这个钥匙还必须随身携带。 另外有时候人不在家,不能开楼下铁门,快递员也没法把东西送上楼。 ......

老邵的开源世界 6549

Codeforces 385C Bear and Prime Numbers(数论)

题目链接:Codeforces 385C Bear and Prime Numbers 题目大意:给出一个长度为n的序列,然后有m次询问,每次询问给出a, b,然后计算[a,b]中所有素数的F(x)之和,F(x)为计算序列中有几个数为x的倍数。 解题思路:数论题,因为内存空间限制为512M,所以可以开的下10^7的数组,然后用筛选法求素数的同时计算个数。 #inclu

不慌不忙、不急不躁 2541

STM32解析航模遥控器的PPM信号

使用STM32对航模遥控器的PPM信号进行解析

qq_44343584的博客 9733

Fofa API高阶玩法:用Python批量获取漏洞资产(含OA系统扫描实战)

本文详细介绍了如何利用Python结合Fofa API实现自动化漏洞资产收集的高阶实战技巧。通过构建健壮的客户端、设计精准查询语法、实现多线程批量采集,并以OA系统漏洞扫描为例,演示了从资产发现、过滤验证到报告生成的全流程,旨在提升安全运维与应急响应的效率。

weixin_28607671的博客 497

C. Bear and Prime Numbers

Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integersx1, x2, ..., xnof lengthnandmqueries, each of them is characterized by t...

wxl7777的博客 411

3U 与 SV630A 伺服实现 CANLINK 通讯

SD410这组参数特别重要,这个32位特别重要,是防止数值乱码的关键。

weixin_42714122的博客 2694

Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers(暴力)

题目链接:点击打开链接 题意:给n个数, m次询问, 每次询问时一个区间[l, r]。 求这个区间中的所有素数,能被n个数中的几个数整除的累加和。 思路:没想到什么好办法, 直接筛出素数以后直接暴力的,没想到跑的这么快。。 最费时间的大概就是那个二重循环, 但是可能因为素数比较少, 所以实际的时间复杂度并不高。 细节参见代码: #include #include #include #in

AC_Arthur的专栏 1453

隐藏技巧!用ArcGIS Pro像素编辑器实现PS级影像编辑(附地貌伪装案例)

本文深入探讨ArcGIS Pro像素编辑器的创意应用,从基础操作到高级影像处理实战,展示了其在城市规划、环境分析等领域的独特价值。通过详细的功能解析和地貌伪装等案例,帮助用户实现媲美专业图像处理软件的精细操作,提升GIS工作效率。

weixin_28520495的博客 335

AD7768与STM32F439的硬件设计避坑指南:如何优化高精度ADC系统的电源与PCB布局

本文详细解析了AD7768与STM32F439在高精度ADC系统硬件设计中的关键问题与优化方案。从电源系统设计、PCB布局到基准电压选型,提供了实用的避坑指南和实测数据,帮助工程师提升系统性能至110dB动态范围。特别强调了SPI信号布线和电源滤波对ADC精度的重要影响。

sugar的博客 735

Bear and Prime NumbersSX(素数筛选)

C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently, the bear started studying dat...

Simone chou... 166

1、开启 Microsoft Power Automate 自动化之旅

本文介绍了 Microsoft Power Automate 的基本概念和其在信息时代自动化需求中的重要作用。Power Automate 是 Power Platform 的一部分,能够通过无代码/低代码的方式自动化处理重复性任务,例如邮件处理、文件复制等,从而提升工作效率。文章还详细讲解了 Power Automate 的核心术语、登录方式、创建第一个流程的操作步骤,并通过示例帮助用户快速上手。无论是终端用户还是管理员,都可以通过本文了解如何利用 Power Automate 实现业务流程自动化。

corn8的博客 169

CF385C-(Bear and Prime Numbers)线性筛素数

题意:给出n个数n (1 ≤ n ≤ 106): x1, x2, ..., xn (2 ≤ xi ≤ 107).             然后m (1 ≤ m ≤ 50000)次查询, [Li, Ri] ;输出每次Li与Ri之间所有素数的P值之和。 每个素数的p值的定义是这样的:P(x)表示在给出的n个数里面有多少个数是x的整数倍数。 解法:在线性筛素数的时候,把每个素数的P值可以直

xiefubao的专栏 984

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

codeforces 385C C. Bear and Prime Numbers(线性筛素数)

题目链接:codeforces 385C题目大意:给出n个数,数据范围10710^7,给出m次查询,每次给出l,r求在l和r之间的素数的∑ki=0f(pi)\sum_{i=0}^kf(p_i),f(pi)f(p_i)定义为n个数中能够整除pip_i的个数。题目分析:直接线性筛素数,记录每个数最大的素因数,然后统计对于每个素因数对应的f(pi)f(p_i),然后求取前缀和,来方便求取区间和。AC代码:

llin-黎辰 1731

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Codeforces 385C Bear and Prime Numbers [素数筛法]

Code: #include #include #include #include #include #include #include #include #include #include #include #include #define INF 0x7fffffff #define SUP 0x80000000 #define mem(a,b) memset(a,b,sizeof(a)

code_or_code 1322

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

CF385C Bear and Prime Numbers 数学

CF385C Bear and Prime Numbers 数学 题意翻译 给你一串数列a.对于一个质数p,定义函数f(p)=a数列中能被p整除的数的个数.给出m组询问l,r,询问[l,r]区间内所有素数p的f(p)之和. 题目描述 Recently, the bear started studying data structures and fa...

loooooog的博客 234

codeforces 385C Bear and Prime Numbers

http://www.elijahqi.win/archives/2940 题意翻译 给你一串数列a.对于一个质数p,定义函数f(p)=a数列中能被p整除的数的个数.给出m组询问l,r,询问[l,r]区间内所有素数p的f(p)之和. 题目描述 Recently, the bear started studying data structures and faced the followi...

Elijahqi 241

Codeforces 385 C. Bear and Prime Numbers

把求和混到求素数里就快多了。。。。 C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recent

码代码的猿猿 2694

CF385C Bear and Prime Numbers(素数+暴力)

线性素数筛出1e7的质数,应该是6e5左右个,然后直接暴力预处理答案即可。复杂度大概在(n/ln n∗logn)(n/ln\ n*log n)左右

Icefox的博客 1522

Codeforces Round #226 (Div. 2)--C. Bear and Prime Numbers

C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently, the bear started studyi

aozil_yang的博客 603

Codeforces 385C Bear and Prime Numbers

题目链接:Codeforces 385C Bear and Prime Numbers 看到"qunwe"

fobdddf的专栏 1323

CF:Problem 385C - Bear and Prime Numbers 预处理DP

C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently, the bear started studyi

liwei的专栏 1373

Codeforces 385 C Bear and Prime Numbers

想法题

Muti-Agent 2838

Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers

C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently, the bear started studyi

小华在努力~ 1310

Codeforces385C Bear and Prime Numbers(数论+打表)

题意:给一个数列(无规则排列,会重复)再给m个查找范围,查询每个查找范围内的素数能整除数列中的数的数量和(有点绕口) 其实这道题本质上不是很难,然后T的我想吐。先筛一个素数表,然后一边打表一边做一个前缀和的统计。我用的类似埃氏筛法做表,因为我之前用欧氏筛法做表,莫名WA了,然后用了比较擅长的埃氏筛法。 T了N次,原因很多,我就不细说了,直接贴代码。 #include&amp;lt;iostrea...

Nero的博客 238
上一篇: codeforces 4D. Mysterious Present
下一篇: codeforces E. Cyclic Components
PinappleMi
博客等级 码龄9年 10粉丝 48原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值