CF1520B 构造

大水题
就看每个范围内有多少个每一位都相同的数
长度为j的每一位都是i的数的公式为: ( p o w ( 10 , j ) − 1 ) / 9 ∗ i (pow(10, j)-1)/9 *i (pow(10,j)1)/9i
每次最多计算 O ( 9 ∗ 9 ∗ 9 ) O(9*9*9) O(999)次,一共计算 1 0 4 ∗ 9 ∗ 9 ∗ 9 10^4*9*9*9 104999

// Problem: B. Ordinary Numbers
// Contest: Codeforces - Codeforces Round #719 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1520/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int n;

int pow1(int n){
	int res = 1;
	while(n--){
		res *= 10;
	}
	return res;
}

int main(){
	cin >> T;
	while(T--){	
		cin >> n;
		ll ans = 0;
		for(int i = 1; i <= 9; i++){
			for(int j = 1; j <= 9; j++){
				int t = pow1(j);
				int x = (t - 1) / 9;
				if(x * i <= n){
					// cout << x * i << endl;
					ans++;
				}
				else break;
			}
		}
		cout << ans << Endl;
	}
	re 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值