Numbers
来源:互联网 发布:工程预算软件哪个好 编辑:程序博客网 时间:2024/05/16 19:56
Description
Let us call P(n) - the product of all digits of number n (in decimal notation).
For example, P(1243)=1*2*4*3=24; P(198501243)=0.
Let us call n to be a good number, if (p(n)<>0) and (n mod P(n)=0).
Let us call n to be a perfect number, if both n and n+1 are good numbers.
You are to write a program, which, given the number K, counts all such
numbers n that n is perfect and n contains exactly K digits in decimal notation.
For example, P(1243)=1*2*4*3=24; P(198501243)=0.
Let us call n to be a good number, if (p(n)<>0) and (n mod P(n)=0).
Let us call n to be a perfect number, if both n and n+1 are good numbers.
You are to write a program, which, given the number K, counts all such
numbers n that n is perfect and n contains exactly K digits in decimal notation.
Input
Only one number K (1<=K<=1000000) is written in input.
Output
Output the total number of perfect k-digit numbers.
Sample Input
Input
1
Output
8
题目大意:
给一个k位的数,问具有k位的数里。有多少个数是perfect number。perfect number题目描述的性质。
我的做法是:看输入数据就知道perfect number必定不会太多.将前几位的数据输出来观察后,找到规律即可解。
#include <iostream>using namespace std;void input(){ long long n; cin >> n; if (n == 1) { cout << 8 << endl; } else if ((n - 1) % 3 == 0) //(n - 1) % 3时多2, 如四位 1111 1112 1115 { if ((n - 1) % 6 == 0) //(n - 1) % 6时多3 如七位 1111111 1111112 1111115 1111116 { cout << 4 << endl; } else { cout << 3 << endl; } } else { cout << 1 << endl; //普通为1 如两位 11 三位 111 }}int main(){ input(); return 0;}
- Numbers
- Numbers
- Numbers
- Numbers
- Numbers
- Ugly Numbers
- Humble Numbers
- Humble Numbers
- Palindrom Numbers
- Niven Numbers
- Alien Numbers
- Alien Numbers
- Phone Numbers
- usaco_humble numbers
- Alien Numbers
- Alien Numbers
- hdu1058humble numbers
- Runaround Numbers
- CSS笔记
- 广语言2051个广命令
- HDU 1335 Basically Speaking(进制转换问题)
- 怎样把地图放入网页中
- 基于VMware的Linux虚拟机硬盘空间扩大
- Numbers
- 写在水上的字
- java开发四步学习网
- UML类图与类的关系详解
- hdu 4674 (缩点 + 倍增LCA)
- 更改文件时间属性需要注意的问题
- 电机驱动的三种脉冲模式
- 二进宫:前交叉韧带重建术后取钉 记录
- DVB PIS 中PAT和PMT编码函数注解