题目大意:
给出一个N,要求求出有多少个2*N位的整数,其前N位组成的数和后N位组成的数都能被2N位的这个整数整除
比如说 n = 1时 11 %1 == 0 && 11 % 1 == 0
15 %1 == 0 && 15 % 5 == 0
那么11和15都是满足条件的数,n = 1时满足条件的数有11,12,15,22,24,33,36,44,48,55,66,77,88,99
一共14个,所以输入 n为1时输出16
大致思路:
假设这个2*N位的整数的前n位形成的数是 k1, 后n位形成的数是 k2
那么,原来的数就是 k1*(10^n) + k2
由于 10^(n - 1) <= k1 <= (10^n) - 1 且 0 <= k2 <= (10^n) - 1
要使得k1*(10^k2) + k2 能被k1, 和 k2 整除,k1*(10^n)/k2 和 k2/k1都必须是整数
当n == 1时, k2/k1 只能是1,2,5,这样(k1/k2) *10 才能是整数
当 n == 2时, k2/k1只能是1,2,4,5这样(k1/k2)*100能是整数
当n >= 3 时, k2/k1可以使1,2,4,5,8这样(k1/k2)*(10^n)能是整数
如此,便可以暴力枚举n <= 5的情况:
n == 1 answer is 14
n == 2 answer is 155
n == 3 answer is 1575
n == 4 answer is 15750
n == 5 answer is 157500 //这个我暴力用的时间久开始比较长了,n == 6就没有继续打了
猜想: n >= 3时答案为 1575 + (n - 3)个零
交上去AC.....打表万岁...
证明不太清楚...
/*
* Author: Gatevin
* Created Time: 2014/7/21 13:32:14
* File Name: hehe.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
int main()
{
int N;
cin>>N;
if(N == 1)
{
cout<<"14\n"<<endl;
return 0;
}
if(N == 2)
{
cout<<"155"<<endl;
return 0;
}
if(N == 3)
{
cout<<"1575"<<endl;
return 0;
}
if(N >= 4)
{
cout<<"1575";
for(int i = 1; i <= N - 3; i++)
{
cout<<"0";
}
cout<<endl;
}
return 0;
}