non-random numbers

来源:互联网 发布:慢慢买数据怎么看 编辑:程序博客网 时间:2024/06/05 01:51
Vasya is a schoolboy who was playing around with a random number generator and 
noticed that it never generates numbers with the value of a specific digit equal to the 
position of that digit in the number. 
Vasya became curious and he came to discover the following:
? The input accepted by the generator is one positive integer n – the 
number of digits in the generated random number.
? The output is a positive integer number consisting of n digits without 
leading zeroes.
? In the generated number at i position (from the left-hand side) cannot be 
digit i.
For example, if we want the generator to produce a single-digit number, it will 
generate any single-digit number except 0 or 1. In case with a double-digit number, 
the output will be anything except 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 32, 42, 
52, 62, 72, 82 or 92.
The schoolboy decided to find out how many different numbers can be generated for 
any given n-digit number. 
Your task is to write a program that will help the schoolboy to solve this problem.
Limitations
1 ≤ n ≤ 100.
Input
The input file contains single integer n – the number of digits in the generated 
random number.
Output
The output file must contain one single integer – the number of possible random n-
digit numbers. The output must have no leading zeroes.
Examples
Input.txt Output.txt
1 8
2 72

12 344373768000


问n位数中第x位不等于x的数的个数


思路:

当n前10时直接相乘

例如8*9*9*9*9....

当n大于9时直接乘10直接加0就可以了

ac代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){    freopen("input.txt","r",stdin);    freopen("output.txt","w",stdout);    long long x;    long long y;    while(scanf("%lld",&y)!=-1)    {        if(y<10)        {            x=8;            for(int i=1;i<y;i++)            x=x*9;            printf("%lld\n",x);        }        else        {            printf("344373768");            for(int i=1;i<=y-9;i++)            printf("0");            printf("\n");        }    }    return 0;}


0 0