2986: Non-Squarefree Numbers

本文介绍了一种算法,用于求解第n个含有平方因子的整数。通过筛选法预先处理出所有小于等于N的整数的平方因子状态,并采用二分查找的方法高效确定目标数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

题目大意:求第n个有平方因子的数

题解:跟[2440]完全平方数基本上一样,取补集就好了

我的收获:~~~

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
const int N=447230;

int p[N+5],u[N+5];
bool vis[N+5];
ll k,ans;

void euler()
{
    u[1]=1;
    for(int i=2;i<=N;i++){
        if(!vis[i]) p[++p[0]]=i,u[i]=-1;
        for(int j=1;j<=p[0]&&p[j]*i<=N;j++){
            vis[p[j]*i]=1;
            if(i%p[j]==0){u[p[j]*i]=0;break;}
            u[p[j]*i]=-u[i];
        }
    }
}

bool check(ll x)
{
    ll ret=x;
    for(ll i=1;i*i<=x;i++)
        ret-=u[i]*(x/(i*i));
    return ret>=k;
}

void work()
{
    cin>>k;
    for(ll l=1,r=3e10;l<=r;){
        ll mid=l+r>>1;
        if(check(mid)) r=mid-1,ans=mid;
        else l=mid+1;
    }
    printf("%lld\n",ans);
}

int main()
{
    euler();
    work();
    return 0;
}
user@debian:~/ModSecurity$ ./build.sh libtoolize: putting auxiliary files in '.'. libtoolize: copying file './ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build'. libtoolize: copying file 'build/libtool.m4' libtoolize: copying file 'build/ltoptions.m4' libtoolize: copying file 'build/ltsugar.m4' libtoolize: copying file 'build/ltversion.m4' libtoolize: copying file 'build/lt~obsolete.m4' configure.ac:50: installing './compile' configure.ac:45: installing './missing' examples/multiprocess_c/Makefile.am: installing './depcomp' src/Makefile.am:70: warning: wildcard actions/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/ctl/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/data/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/disruptive/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/transformations/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard debug_log/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard audit_log/writer/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard collection/backend/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard operators/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard parser/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard request_body_processor/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard utils/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard variables/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard engine/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard *.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/ctl/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/data/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/disruptive/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/transformations/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard debug_log/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard audit_log/writer/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard collection/backend/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard operators/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard parser/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard request_body_processor/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard utils/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard variables/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard engine/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard *.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) user@debian:~/ModSecurity$
最新发布
06-29
<think>我们正在处理用户关于ModSecurity构建过程中出现的警告问题。用户特别关注在运行build.sh脚本时出现的关于Makefile.am中使用非POSIX变量名的警告。这些警告出现在src/Makefile.am的第70行,涉及多个通配符表达式(如`actions/*.h`)。用户想知道这些警告的原因、是否可以安全忽略以及如何修复。 ###问题分析1.**警告内容**:-构建过程中出现多行警告:`warning:wildcard...:non-POSIXvariable name`-示例:`src/Makefile.am:70: warning: wildcard actions/*.h:non-POSIXvariable name`-括号内提示:`(probably aGNU makeextension)` 2. **原因**:-Automake严格遵循POSIX标准,而GNU Make支持通配符(wildcard)等扩展功能。-在Makefile.am中直接使用通配符(如`*.h`)属于GNUMake的扩展语法,不符合POSIX标准。-Automake在解析时会产生警告,但实际生成的Makefile仍能正常工作(因为最终由GNUMake处理)。 3. **影响**:-这些警告**不会中断构建过程**,属于代码风格警告。-生成的Makefile在GNUMake环境下能正确执行,因为GNU Make支持通配符。-如果目标系统使用非GNU Make(如BSD Make),则可能出错。 ###解决方案####选项1:忽略警告(推荐) -**适用场景**:仅在GNUMake环境下构建(Linux系统默认使用GNUMake)。- **理由**:ModSecurity项目明确设计为使用GNUMake,因此这些警告可安全忽略。 -**验证方法**:构建完成后,检查生成的`Makefile`中是否包含通配符表达式(通常保留)。 ####选项2:修改Makefile.am(高级用户) -**原理**:将通配符替换为显式文件列表。 -**步骤**:1.编辑`src/Makefile.am`:```makefile#原始问题行(示例):# some_variable =actions/*.h actions/ctl/*.h ...#修改为显式列出文件(假设actions目录下有foo.h bar.h):some_variable =actions/foo.hactions/bar.hactions/ctl/ctl1.h ...```2.重新运行`./build.sh`。 -**缺点**:-每次新增/删除头文件都需要手动更新列表。-不推荐,因为ModSecurity项目本身使用通配符管理大量文件。####选项3:抑制Automake警告- **原理**:在`configure.ac`中设置`AM_INIT_AUTOMAKE`时添加`-Wno-portability`选项。 -**步骤**:1.编辑`configure.ac`:```m4AM_INIT_AUTOMAKE([-Wno-portabilityforeign subdir-objects])```2.重新运行`./build.sh`。- **影响**:全局禁用可移植性警告,可能掩盖其他问题。 ###根本原因说明Automake分为两个阶段:1.**生成阶段**:由`automake`解析`Makefile.am`并生成`Makefile.in`。-此阶段严格检查POSIX合规性,产生警告。 2. **执行阶段**:由`configure`生成最终`Makefile`,并由`make`执行。- GNUMake支持通配符,因此实际构建不受影响。###验证修复-忽略警告:构建成功后,检查`mod_security2.so`(或目标文件)是否生成。-修改Makefile.am:确保显式文件列表完整,构建无文件缺失错误。-抑制警告:重新运行`./build.sh`后警告消失。###附加建议-**报告问题**:若警告过多,可向ModSecurity项目提Issue建议使用显式文件列表(但通常不被接受,因通配符更易维护)[^1]。§§相关问题§§1. Automake和Autoconf在构建系统中的角色是什么? 2. GNUMake与POSIXMake的主要区别有哪些? 3.如何为开源项目贡献构建系统的改进?4.ModSecurity的构建依赖哪些外部库?[^1]:Automake官方文档:https://www.gnu.org/software/automake/manual/automake.html</think>### ModSecurity构建中非POSIX变量名警告分析 您在运行ModSecurity的`build.sh`脚本时遇到的警告信息是Automake工具对`Makefile.am`中GNU Make扩展语法的合规性提示。这些警告的核心问题是: ```bash src/Makefile.am:70: warning: wildcard actions/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) ``` #### 原因分析 1. **POSIX标准差异**: - Automake严格遵循POSIX标准 - 通配符表达式(如`*.h`)属于GNU Make扩展语法 - 在POSIX标准中,变量名只能包含字母、字和下划线[^1] 2. **技术本质**: ```makefile # Makefile.am中的问题代码示例 HEADERS = actions/*.h actions/ctl/*.h # 非POSIX合规 ``` 这种通配符语法在GNU Make中有效,但不符合POSIX标准 3. **项目背景**: - ModSecurity使用通配符简化头文件管理 - 这种写法在Linux环境中普遍使用但技术上不规范 #### 解决方案 ##### 方案1:安全忽略(推荐) - **适用场景**:仅在GNU Make环境构建(所有Linux发行版默认) - **操作建议**: ```bash # 添加抑制警告参 ./build.sh 2>&1 | grep -v "non-POSIX variable name" ``` - **验证方法**: ```bash make -p | grep "GNU Make" # 确认使用GNU Make ``` ##### 方案2:代码级修复(高级) ```diff # 修改src/Makefile.am - HEADERS = actions/*.h actions/ctl/*.h ... + actions_headers = $(wildcard actions/*.h) + ctl_headers = $(wildcard actions/ctl/*.h) + HEADERS = $(actions_headers) $(ctl_headers) ... ``` ##### 方案3:全局配置 在`configure.ac`中添加: ```m4 AM_INIT_AUTOMAKE([-Wno-portability]) ``` #### 影响评估 | 方案 | 安全性 | 维护性 | 兼容性 | |------|--------|--------|--------| | 忽略警告 | ✅ 安全 | ✅ 无需维护 | ✅ 全GNU环境 | | 修改代码 | ⚠️ 需测试 | ❌ 增加维护 | ✅ 全环境 | | 配置抑制 | ✅ 安全 | ✅ 一次配置 | ⚠️ 仅Automake | #### 根本原因说明 Automake的检查流程: 1. 解析`Makefile.am`生成`Makefile.in` 2. 严格检查POSIX合规性(阶段1) 3. 最终由GNU Make执行(阶段2) $$ \text{Automake} \xrightarrow{\text{POSIX检查}} \text{Makefile.in} \xrightarrow{\text{GNU Make}} \text{二进制} $$ 通配符警告仅发生在阶段1,不影响阶段2的实际构建[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值