C. Removing Smallest Multiples(Div. 2 C)

Problem - C - Codeforces

 

题目意思:给你一个 集合 S 这个 集合里的元素是 1 ~ n,每次操作可以 选择一个数 k,并删除 集合 s 中 最小的 k 的倍数

 思路: 从小到大遍历存就可以了(md一直以为会T结果没点事)

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
char s[N];
int q[N];

int main()
{
	
	int t;
	sc_int(t);

	while(t--)
	{
		memset(q,0,sizeof q);		
		sc_int(n);
		cin>>s+1;
	
	
		for(int i =1;i<=n;i++)
		{
			if(s[i]=='0')
			for (int j = i; j <= n; j += i)
			{
				if(s[j]=='1')break; 
				if(!q[j]){
				q[j]=i;
				}			
			}
		}
		ll res=0;
		for(int i =1;i<=n;i++)
		{
			if(s[i]=='0'){
			res+=q[i];
			q[i]=0;
			}
		}
		pr_ll_n(res);

	}
	
	return 0;
}

root@sw:~/Serve/vscode# chmod 777 uninstall.sh root@sw:~/Serve/vscode# ./uninstall.sh Reading package lists... Done Building dependency tree... Done Reading state information... Done No apt package "code", but there is a snap with that name. Try "snap install code" E: Unable to locate package code Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages will be REMOVED: libauthen-sasl-perl* libclone-perl* libdata-dump-perl* libencode-locale-perl* libfile-basedir-perl* libfile-desktopentry-perl* libfile-listing-perl* libfile-mimeinfo-perl* libfont-afm-perl* libhtml-form-perl* libhtml-format-perl* libhtml-parser-perl* libhtml-tagset-perl* libhtml-tree-perl* libhttp-cookies-perl* libhttp-daemon-perl* libhttp-date-perl* libhttp-message-perl* libhttp-negotiate-perl* libio-html-perl* libio-socket-ssl-perl* libio-stringy-perl* libipc-system-simple-perl* liblwp-mediatypes-perl* liblwp-protocol-https-perl* libmailtools-perl* libnet-dbus-perl* libnet-http-perl* libnet-smtp-ssl-perl* libnet-ssleay-perl* libproxychains3* libtie-ixhash-perl* libtimedate-perl* libtry-tiny-perl* liburi-perl* libwww-perl* libwww-robotrules-perl* libx11-protocol-perl* libxml-parser-perl* libxml-twig-perl* libxml-xpathengine-perl* mesa-utils-bin* perl-openssl-defaults* xdg-utils* 0 upgraded, 0 newly installed, 44 to remove and 26 not upgraded. After this operation, 8,426 kB disk space will be freed. (Reading database ... 110336 files and directories currently installed.) Removing libauthen-sasl-perl (2.1600-1.1) ... Removing libclone-perl (0.45-1build3) ... Removing libdata-dump-perl (1.25-1) ... Removing libnet-dbus-perl (1.2.0-1build3) ... Removing libxml-twig-perl (1:3.52-1) ... Removing libxml-parser-perl:amd64 (2.46-3build1) ... Removing libhttp-daemon-perl (6.13-1ubuntu0.1) ... Removing libfile-mimeinfo-perl (0.31-1) ... Removing libfile-desktopentry-perl (0.22-2) ... Removing libfile-basedir-perl (0.09-1) ... Removing libhtml-format-perl (2.12-1.1) ... Removing libfont-afm-perl (1.20-3) ... Removing libhtml-form-perl (6.07-1) ... Removing libmailtools-perl (2.21-1) ... Removing libnet-smtp-ssl-perl (1.04-1) ... Removing libio-stringy-perl (2.111-3) ... Removing libipc-system-simple-perl (1.30-1) ... Removing libproxychains3:amd64 (3.1-9) ... Removing libtie-ixhash-perl (1.23-2.1) ... Removing libx11-protocol-perl (0.56-7.1) ... Removing libxml-xpathengine-perl (0.14-1) ... Removing mesa-utils-bin:amd64 (8.4.0-1ubuntu1) ... Removing xdg-utils (1.1.3-4.1ubuntu3~22.04.1) ... Removing liblwp-protocol-https-perl (6.10-1) ... Removing libwww-perl (6.61-1) ... Removing libfile-listing-perl (6.14-1) ... Removing libhtml-tree-perl (5.07-2) ... Removing libhtml-parser-perl:amd64 (3.76-1build2) ... Removing libhtml-tagset-perl (3.20-4) ... Removing libhttp-cookies-perl (6.10-1) ... Removing libhttp-negotiate-perl (6.01-1) ... Removing libio-socket-ssl-perl (2.074-2) ... Removing libnet-http-perl (6.22-1) ... Removing libnet-ssleay-perl:amd64 (1.92-1build2) ... Removing libtry-tiny-perl (0.31-1) ... Removing libwww-robotrules-perl (6.02-1) ... Removing perl-openssl-defaults:amd64 (5build2) ... Removing libhttp-message-perl (6.36-1) ... Removing libencode-locale-perl (1.05-1.1) ... Removing libhttp-date-perl (6.05-1) ... Removing libio-html-perl (1.004-2) ... Removing liblwp-mediatypes-perl (6.04-1) ... Removing libtimedate-perl (2.3300-2) ... Removing liburi-perl (5.10-1) ... Processing triggers for man-db (2.10.2-1) ... Processing triggers for libc-bin (2.35-0ubuntu3.9) ... Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu jammy InRelease Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates InRelease [128 kB] Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-backports InRelease Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-security InRelease [129 kB] Ign:5 https://download.docker.com/linux/ubuntu jammy InRelease Hit:5 https://download.docker.com/linux/ubuntu jammy InRelease Hit:6 https://packages.emqx.com/emqx/emqx/ubuntu jammy InRelease Fetched 257 kB in 3s (94.1 kB/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done 26 packages can be upgraded. Run 'apt list --upgradable' to see them. Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). 验证结果: [成功] VSCode二进制文件已移除 [警告] 存在残留进程 root@sw:~/Serve/vscode# 怎么解决?
05-13
PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> cd E:\PyTorch_Build\pytorch PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\activate (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 确保当前在 pytorch 源码目录 (rtx5070_env) PS E:\PyTorch_Build\pytorch> cd E:\PyTorch_Build\pytorch (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 删除构建目录(如果存在) (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item -Recurse -Force build -ErrorAction SilentlyContinue (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item -Recurse -Force .cmake_build -ErrorAction SilentlyContinue (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 删除可能的临时文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item -Recurse -Force *.egg-info -ErrorAction SilentlyContinue (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item -Recurse -Force dist -ErrorAction SilentlyContinue (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 谨慎操作!以下命令会删除所有未跟踪的源码文件(除了您自己的修改)。 (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 如果您在源码中有任何重要更改,请先备份。 (rtx5070_env) PS E:\PyTorch_Build\pytorch> git clean -xdf Removing CMakeFiles/ Removing CTestTestfile.cmake Removing Repair-Libuv.ps1 Removing __pycache__/ Removing adaptive_builder.ps1 Removing analyze_cudnn.ps1 Removing architecture_patch.py Removing aten/src/ATen/Config.h Removing aten/src/ATen/cuda/CUDAConfig.h Removing build.log Removing build_20250902_220733.log Removing build_20250902_230239.log Removing build_20250902_230532.log Removing build_20250902_230545.log Removing build_20250902_230555.log Removing build_20250902_230603.log Removing build_custom.ps1 Removing build_enhanced.ps1 Removing build_error.log Removing build_fixed.ps1 Removing build_fixed_v2.ps1 Removing build_log.txt Removing build_openblas_from_source.ps1 Removing build_openblas_no_asm.ps1 Removing build_optimized.ps1 Removing build_optimized_v10.ps1 Removing build_optimized_v11.ps1 Removing build_optimized_v2.ps1 Removing build_optimized_v3.ps1 Removing build_optimized_v4.ps1 Removing build_optimized_v5.ps1 Removing build_optimized_v6.ps1 Removing build_optimized_v8.ps1 Removing build_out/ Removing build_pytorch_cuda.ps1 Removing build_safe_v1.ps1 Removing build_simple.ps1 Removing clean_and_setup.ps1 Removing cmake/Cuda.cmake Removing cmake/Modules/FindLibuv.cmake Removing cmake/Modules/win_toolchain.cmake Removing cmake_config.ps1 Removing cmake_install.cmake Removing compile_cuda_test.ps1 Removing compile_cudnn912.ps1 Removing compile_win.ps1 Removing compile_win_fixed.ps1 Removing complete_install_fix.ps1 Removing configure_cudnn.ps1 Removing create_missing_cmake.ps1 Removing cuda_test.cpp Removing cuda_test.cu Removing cuda_test.exe Removing cuda_test.py Removing cudnn_compat.patch Removing cudnn_path_mapper.py Removing dependency_resolver.py Removing diagnose.py Removing diagnose_fixed.py Removing diagnose_fixed_v3.py Removing diagnose_fixed_v4.py Removing diagnose_fixed_v5.py Removing diagnose_fixed_v6.py Removing diagnose_fixed_v8.py Removing diagnostic_test.py Removing download_enhanced.ps1 Removing enhanced_diagnostic.py Removing enhanced_file_search.ps1 Removing enhanced_test.py Removing env_diagnostic.ps1 Removing environment_blueprint.psd1 Removing fallback_to_cpu.py Removing fbgemm_fix.patch Removing find_cuda_path(v2).ps1 Removing find_cuda_path.ps1 Removing find_cudnn.ps1 Removing find_cudnn_fixed.ps1 Removing find_cudnn_path.ps1 Removing fix_cudnn_path.ps1 Removing fix_encoding.ps1 Removing fix_environment.ps1 Removing fixed_build_openblas.ps1 Removing fixed_build_openblas_from_source.ps1 Removing fixed_build_script.ps1 Removing fixed_compile.ps1 Removing fixed_complete_install_fix.ps1 Removing fixed_diagnostic_test.py Removing fixed_hash_validation.ps1 Removing fixed_manual_build.ps1 Removing full_build.ps1 Removing full_fix_script.ps1 Removing functorch/_C.cp310-win_amd64.pyd Removing functorch/functorch.pyd Removing generate_compat.py Removing gpu_compatibility.py Removing install/ Removing install_openblas.ps1 Removing install_openblas_enhanced.ps1 Removing install_openblas_fixed.ps1 Removing install_openblas_mirror.ps1 Removing install_openblas_mirror_fixed.ps1 Removing install_openblas_ps7.ps1 Removing load_vs_env.ps1 Removing manual_build.ps1 Removing manual_install_openblas.ps1 Removing openblas.zip Removing pagefile.sys Removing prepare_build.ps1 Removing pytorch_fix_cmake.ps1 Removing rtx5070_env/ Removing rtx5070_test.py Removing setup_compiler.ps1 Removing setup_environment.ps1 Removing test.cpp Removing test.cu Removing test_gpu.exe Removing test_gpu.py Removing test_simple.py Removing third_party/cuda_compat/ Removing third_party/libuv/ Removing third_party/nccl/ Removing tools/__pycache__/ Removing tools/generate_missing_symbols.py Removing tools/setup_helpers/__pycache__/ Removing tools/shared/_utils_internal.py Removing torch/csrc/CMakeLists.txt Removing torch/csrc/api/include/torch/version.h Removing torchgen/__pycache__/ Removing torchgen/aoti/__pycache__/ Removing torchgen/api/__pycache__/ Removing torchgen/api/types/__pycache__/ Removing torchgen/dest/__pycache__/ Removing torchgen/packaged/ Removing torchgen/selective_build/__pycache__/ Removing use_precompiled.ps1 Removing verify_cuda.ps1 Removing verify_final.py Removing verify_final_v2.py Removing verify_installation.ps1 Removing verify_openblas.ps1 Removing verify_openblas_fixed.ps1 Removing verify_paths.ps1 Removing verify_pytorch.ps1 Removing verify_pytorch.py Removing verify_pytorch_fixed.py Removing verify_pytorch_fixed_v2.py Removing verify_torch.py Removing vs_env_setup.ps1 Removing windows_pytorch_deps.ps1 Removing "\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 仅重置已跟踪的文件,丢弃所有修改(如果您确认不需要任何源码改动) (rtx5070_env) PS E:\PyTorch_Build\pytorch> git reset --hard HEAD is now at 2d31c3d99d9 Pass shared_ptr by value (#161834) (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 执行最终构建脚本 (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\build_final.ps1 &: E:\PyTorch_Build\pytorch\build_final.ps1:11 Line | 11 | & ".\rtx5070_env\Scripts\activate.ps1" | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | The term '.\rtx5070_env\Scripts\activate.ps1' is not recognized as a name of a cmdlet, function, script file, or | executable program. Check the spelling of the name, or if a path was included, verify that the path is correct | and try again. (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 尝试添加可能支持的计算能力 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:TORCH_CUDA_ARCH_LIST = "8.9;9.0" (rtx5070_env) PS E:\PyTorch_Build\pytorch> pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu130 Looking in indexes: https://download.pytorch.org/whl/nightly/cu130 ERROR: Could not find a version that satisfies the requirement torch (from versions: none) ERROR: No matching distribution found for torch (rtx5070_env) PS E:\PyTorch_Build\pytorch>
09-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值