吸血鬼数字

本文介绍了吸血鬼数字的概念及其发现历史,展示了如何通过编程找出特定条件下的吸血鬼数字,如由两个两位数相乘得到的四位数吸血鬼数字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       吸血鬼数字是指位数为偶数的数字,可以由一对数字相乘而得到,而这对数字各包含乘积的一半位数的数字,其中从最初的数字中选取的数字可以任意排序。以两个0结尾的数字是不允许的,例如,下列数字都是“吸血鬼”数字:
  1260 = 21 * 60
  1827 = 21 * 87
  2187 = 27 * 81

  1994年柯利弗德·皮寇弗在Usenet社群sci.math的文章中首度提出吸血鬼数。后来皮寇弗将吸血鬼数写入他的书Keys to Infinity的第30章。

------以上摘自百度百科。

/*
  Name: 吸血鬼数字
  Author: Mcdragon
  Date: 05-03-12 00:16
  Description:  一个四位数字由两个两位数相乘得到,两个两位数的各位构成了这个四位数
*/

#include <iostream>
using namespace std;
void GetVanpireNumber(void);
bool IsContain(int iNum, int head, int tail);
int main()
{
  GetVanpireNumber();
  system("PAUSE");
  return 0;
}

void GetVanpireNumber(void)
{
  int head, tail, iNum;
  for (head = 10; head < 100; ++head)
  {
    for (tail = 10; tail < head; ++tail)
    {
      iNum = head * tail;
      if (iNum > 1000 && IsContain(iNum, head, tail))
        cout << "There is a VanpireNumber: " << iNum
             << "= " << head << " * " << tail <<endl; 
    }
  }
}

bool IsContain(int iNum, int head, int tail)
{
  int a[10] = {0};
  while (head)
  {
    a[head % 10]++;
    head /= 10;
  }
  while (tail)
  {
    a[tail % 10]++;
    tail /= 10;
  }
  while (iNum)
  {
    a[iNum % 10]--;
    iNum /= 10;
  }
  for (int i = 0; i < 10; ++i)
  {  
    if (a[i])
      return false;
  }
  return true;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值