1 条题解

  • 0
    @ 2025-12-9 15:49:28

    位数不超过n的正整数,即<10^n的正整数,从1到10^n-1一个个数字去枚举即可。

    #include<bits/stdc++.h>
    
    using namespace std;
    
    
    int main()
    {
    	int n,k;
    	cin>>n>>k;
    	int ans=0;
    	for(int i=1;i<pow(10,n);i++){
    		int tmp=i;
    		int tot=0;
    		while(tmp){
    			tot+=tmp%10;
    			tmp/=10;
    		}
    		if(tot<=k)ans++;
    	}
    	cout<<ans;
    	return 0;
    }
    
    • 1

    信息

    ID
    9656
    时间
    1000ms
    内存
    512MiB
    难度
    1
    标签
    递交数
    39
    已通过
    20
    上传者