包含1号 [英] Numbers that contain a 1

查看:118
本文介绍了包含1号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能找到QT。号包括一个1在段[1..N]? 例如:当n = 29是12;当n = 100是20。 n可以达到10 ^ 9,期限为2秒。 语言C ++

How can i find qt. numbers includes a 1 in the segment [1..n]? eg: for n=29 it is 12; for n=100 it is 20. n can reach 10^9 and time limit is 2 sec. language C++

推荐答案

一个简单的方法来检查,如果单号是计算其模10:如果是1,那么它,另有10并重复划分它。如果该数字是0,它不包括1

A simple way to check if a single number is to compute its modulo 10: if it's 1 then it does, otherwise divide it by 10 and repeat. If the number is 0, it doesn't include 1.

这应该足以让你开始。

这篇关于包含1号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆