当前位置:网站首页>sum of special numbers
sum of special numbers
2022-08-01 06:33:00 【Ding Jiaxiong】
题目
小明对数位中含有 2、0、1、9 的数字很感兴趣(不包括前导 0),在 1 到 40 中这样的数包括 1、2、9、10 至 32、39 和 40,共 28 个,他们的和是 574.
请问,在 1 到 n 中,所有这样的数的和是多少?
输入格式
共一行,包含一个整数 n.
输出格式
共一行,包含一个整数,表示满足条件的数的和.
数据范围
1≤n≤10000
输入样例:
40
输出样例:
574
思路分析
题解
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int res = 0;
for(int i = 1; i <= n; i++){
int x = i;
while(x){
int t = x % 10; //取出
x /= 10; //删掉
//判断
if(t == 2 || t == 0 || t == 1 || t == 9){
res += i;
break;
}
}
}
cout << res << endl;
return 0;
}
边栏推荐
- Matlab simulink particle swarm optimization fuzzy pid control motor pump
- Dell PowerEdge Server R450 RAID Configuration Steps
- 爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
- 信息系统项目管理师必背核心考点(五十六)配置控制委员会(CCB)的工作
- uva12326
- More than 2022 cattle guest school game 4 yue
- 「面经分享」西北大学 | 字节 生活服务 | 一面二面三面 HR 面
- flinkcdc对mysql的date字段类型转化有什么解决思路么
- Flip letters using string container
- AspNet.WebApi.Owin custom Token request parameters
猜你喜欢
WebSocket implements chat function
"By sharing" northwestern university life service | | bytes a second interview on three sides by HR
LeetCode 0149. 直线上最多的点数
MySQL row locks and gap locks
leetcode125 验证回文串
Windows taskbar icon abnormal solution
Win任务栏图标异常解决
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
Malicious attacks on mobile applications surge by 500%
随机推荐
Selenium: Element wait
mysql的行锁和间隙锁
leetcode43 字符串相乘
Guest brush SQL - 2
仿牛客网讨论社区项目—项目总结及项目常见面试题
Selenium: Introduction
信息系统项目管理师必背核心考点(五十六)配置控制委员会(CCB)的工作
MVVM project development (commodity management system 1)
uva12326
微信小程序用户登录auth.code2Session接口开发
数据机构----线性表之单向链表
微信小程序接口调用凭证(获取token)auth.getAccessToken接口开发
从零开始—仿牛客网讨论社区项目(一)
可视化全链路日志追踪
ORACLE modify another user package (package)
NDK does not contain any platforms problem solving
LeetCode 0150. Reverse Polish Expression Evaluation
特别数的和
实战演练 Navicat 中英文模式切换
How JS works