URAL 1385 Interesting Number

Description

Tyomitch calls the number with 2  N digits (without leading zeroes) "interesting", if it's divisible by both the number formed from its first N digits and the number formed from its last  N digits. For example, 1020 is "interesting" (divisible by 10 and 20) and 2005 is not. Tyomitch wants to know how many "interesting" 2  N-digit numbers exist. You are to help him.

Input

Input contains an integer  N (1 ≤  N ≤ 10000).

Output

Output the number of "interesting" 2  N-digit numbers.

Sample Input

input output
1
14

Notes

11, 12, 15, 22, 24, 33, 36, 44, 48, 55, 66, 77, 88, 99.


脑洞题。。打表可以看出来大致的规律。

还有一种方法 

把这个数写成 a*10^n+b,则满足条件等价于b%a=0 and a*10^n%b=0,令 b=ka,则10^n%c=0。且a和b都是n位数。

当 n==1 c可为 1 2 5;当 n==2 c可为 1 2 4 5;n>=3 c可为1 2 4 5 8.

当a为n位数时,要控制a的范围保证b也是n位数。显然,n==1 ans=14,n==2 ans=155

n>=3时,令 a = 10^(n+1)

则(a/8-a/10)*5+(a/5-a/8)*4+(a/4-a/5)*3+(a/2-a/4)*2+(a-a/2)*5=63/40*(10^n)


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int n;
int main()
{

    while(~scanf("%d",&n))
    {
        if(n==1) cout<<14<<endl;
        else if(n==2) cout<<155<<endl;
        else
        {
            cout<<1575;
            for(int i=0;i<n-3;i++)
            cout<<0;
            cout<<endl;
        }
    }
    return 0;
}








你可能感兴趣的:(URAL 1385 Interesting Number)