2021-07-31Mod, Or and Everything

本文揭示了通过暴力计算前100个数的模式,发现答案呈现2的幂次方规律。作者进一步利用此规律,优化代码实现,展示了如何使用递推计算得到每个数的对应值。

先暴力打出来前100个然后找规律

#include<bits/stdc++.h>
using namespace std;
#define int long long
int T;
int x;
signed main(){
    //cin>>T;
    for(int i=1;i<=100;i++){
        x=i;
        int ans=0;
        for(int i=2;i<=x;i++)ans|=x%i;
        cout<<ans<<endl;
    }
}

0
0
1
1
3
3
3
3
7
7
7
7
7
7
7
7
15
15
15
15
15
15
15
15
15
15
15
15
15
15
15
15
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63
63


发现规律就是2的n次方个2的n次方
然后写出代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
int T;
int x;
int a[41];
int sum[41];
signed main(){
    a[0]=1;
    sum[0]=1;
    for(int i=1;i<=39;i++)a[i]=a[i-1]*2 , sum[i]=sum[i-1]+a[i];
    cin>>T;
    while(T--){
        cin>>x;
        if(x==1||x==2)cout<<"0"<<endl;
        else{
            x--;
            for(int i=1;i<=39;i++){
                if(x<=sum[i]){
                    cout<<a[i]-1<<endl;
                    break;
                }
            }
        }

    }
    
}
[dragon@localhost ~]$ rpm -qa | grep qt5-qtbase # 查看当前版本 qt5-qtbase-postgresql-5.11.1-23.ky10.x86_64 qt5-qtbase-mysql-5.11.1-23.ky10.x86_64 qt5-qtbase-common-5.11.1-23.ky10.noarch qt5-qtbase-gui-5.11.1-23.ky10.x86_64 qt5-qtbase-5.11.1-23.ky10.x86_64 [dragon@localhost ~]$ strings /usr/lib64/libQt5Core.so.5 | grep "Qt_5\." # 检查符号版本 Qt_5.11.1_PRIVATE_API Qt_5.0 Qt_5.1 Qt_5.2 Qt_5.3 Qt_5.4 Qt_5.5 Qt_5.6 Qt_5.7 Qt_5.8 Qt_5.9 Qt_5.10 Qt_5.11 [dragon@localhost ~]$ sudo yum install -y https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm Last metadata expiration check: 0:18:08 ago on 2025年11月03日 星期一 19时03分31秒. [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [FAILED] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [dragon@localhost ~]$ sudo ldconfig [dragon@localhost ~]$ echo 'export PATH=$PATH:/usr/lib/virtualbox' | sudo tee -a /etc/profile export PATH=$PATH:/usr/lib/virtualbox [dragon@localhost ~]$ source /etc/profile [dragon@localhost ~]$ sudo /sbin/vboxconfig # 查看详细错误 vboxdrv.sh: Stopping VirtualBox services. vboxdrv.sh: Starting VirtualBox services. vboxdrv.sh: Building VirtualBox kernel modules. vboxdrv.sh: failed: Look at /var/log/vbox-setup.log to find out what went wrong. There were problems setting up VirtualBox. To re-start the set-up process, run /sbin/vboxconfig as root. If your system is using EFI Secure Boot you may need to sign the kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load them. Please see your Linux system's documentation for more information. [dragon@localhost ~]$ dmesg | grep vboxdrv # 检查内核日志 dmesg: 读取内核缓冲区失败: 不允许的操作 [dragon@localhost ~]$ sudo yum install -y kernel-devel-$(uname -r) gcc make Last metadata expiration check: 0:19:01 ago on 2025年11月03日 星期一 19时03分31秒. Package kernel-devel-4.19.90-23.59.v2101.ky10.x86_64 is already installed. Package gcc-7.3.0-20190804.h30.p05.ky10.x86_64 is already installed. Package make-1:4.2.1-15.ky10.x86_64 is already installed. Dependencies resolved. Nothing to do. Complete! [dragon@localhost ~]$ # 生成密钥 sudo mokutil --import MOK.der # 导入密钥(需设置密码) [dragon@localhost ~]$ sudo openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=VirtualBox/" Generating a RSA private key ..............................+++++ ..........+++++ writing new private key to 'MOK.priv' ----- [dragon@localhost ~]$ sudo mokutil --import MOK.der # 导入密钥(需设置密码)input password: input password again: [dragon@localhost ~]$ sudo rpm -ivh VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm 警告:VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 2980aecf: NOKEY 错误:依赖检测失败: libQt5Core.so.5(Qt_5.12)(64bit) 被 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 需要 libSDL-1.2.so.0()(64bit) 被 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 需要 libvpx.so.5()(64bit) 被 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 需要 [dragon@localhost ~]$ sudo VBoxManage extpack install Oracle_VM*.vbox-extpack --accept-license=56be48f923303c8cbabbgbbg WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel (4.19.90-23.59.v2101.ky10.x86_64) or it failed to load. Please recompile the kernel module and install it by sudo /sbin/vboxconfig You will not be able to start VMs until this problem is fixed. VBoxManage: error: Failed to create the VirtualBox object! VBoxManage: error: Code NS_ERROR_FACTORY_NOT_REGISTERED (0x80040154) - Class not registered (extended info not available) VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start. [dragon@localhost ~]$ sudo rpm -ivh VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm --nodeps 警告:VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 2980aecf: NOKEY Verifying... ################################# [100%] 准备中... ################################# [100%] 软件包 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 已经安装 [dragon@localhost ~]$ sudo VBoxManage extpack install Oracle_VM*.vbox-extpack --accept-license=56be48f923303c8cbabbgbbg WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel (4.19.90-23.59.v2101.ky10.x86_64) or it failed to load. Please recompile the kernel module and install it by sudo /sbin/vboxconfig You will not be able to start VMs until this problem is fixed. VBoxManage: error: Failed to create the VirtualBox object! VBoxManage: error: Code NS_ERROR_FACTORY_NOT_REGISTERED (0x80040154) - Class not registered (extended info not available) VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start. [dragon@localhost ~]$ VBoxManage list extpacks | grep "Extension Packs" VBoxManage: error: Failed to create the VirtualBox object! VBoxManage: error: Code NS_ERROR_FACTORY_NOT_REGISTERED (0x80040154) - Class not registered (extended info not available) VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start.
最新发布
11-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值