题意:

1406357289是一个0至9全数字数,因为它由0到9这十个数字排列而成;但除此之外,它还有一个有趣的性质:子串的可整除性。记d1是它的第一个数字,d2是第二个数字,依此类推,我们注意到:

  • d2d3d4=406能被2整除
  • d3d4d5=063能被3整除
  • d4d5d6=635能被5整除
  • d5d6d7=357能被7整除
  • d6d7d8=572能被11整除
  • d7d8d9=728能被13整除
  • d8d9d10=289能被17整除

找出所有满足同样性质数,并求它们的和。


/*************************************************************************
> File Name: euler043.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月27日 星期二 10时36分23秒
************************************************************************/ #include <stdio.h>
#include <inttypes.h>
#include <algorithm> bool IsSubStringDivisibility (int32_t *num) {
int32_t p[7] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 };
int32_t tmp = 0;
for (int32_t i = 1 ; i < 8 ; i++) {
tmp = num[i] * 100 + num[i + 1] * 10 + num[i + 2];
if (tmp % p[i -1]) return false;
}
return true;
}
int32_t main() {
int32_t num[10];
int64_t sum = 0 , tmp;
for (int32_t i = 0 ; i < 10 ; i++) num[i] = i;
do {
if (IsSubStringDivisibility(num)) {
tmp = 0;
for(int32_t i = 0 ; i < 10 ; i++){
tmp = tmp * 10 + (int64_t)num[i];
}
sum += tmp;
}
}while (std::next_permutation(num , num + 10));
printf("%"PRId64"\n",sum);
return 0;
}

Project Euler 43 Sub-string divisibility的更多相关文章

  1. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  2. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  3. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  4. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  5. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  6. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  7. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  8. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  9. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

随机推荐

  1. 解决ubuntu下wordpress设置固定链接后文章无法打开

    1.首先查看是否开启了Apache的rewrite功能,新建一个phpinfo的php文档 <?php phpinfo(); ?> 保存为info.php文件 放在www目录下并用浏览器打 ...

  2. rabbit-入门

    #启用rabbit的web管理 rabbitmq-plugins.bat enable rabbitmq_management 发布的窗口用TOPIC模式 rabbitmq没有确认消息接收的返回值,M ...

  3. PAT Perfect Sequence (25)

    题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  4. android制作闪动的红心

    先上一张效果图吧: 说说这个东西的来源吧.今天突然想到笛卡尔心形图,想去看看能不能画个心出来,可是看到一篇不错的文章,那篇文章罗列了非常多关于心形的函数方程,这可把我高兴坏了,于是我选取了一个比較好看 ...

  5. DexClassLoader和PathClassLoader类载入机制

    0x00 在DexClassLoader和PathClassLoader载入Dex流程一文中,我们分析了dex文件怎样形成了DexFile结构体.本文中解说类载入机制,实际上就是生成ClassObje ...

  6. 基于FPGA的VGA可移植模块终极设计【转】

    本文转载自:http://www.cnblogs.com/lueguo/p/3373643.html 略过天涯   基于FPGA的VGA可移植模块终极设计 一.VGA的诱惑 首先,VGA的驱动,这事, ...

  7. linux udev 机制【转】

    本文转载自:http://blog.csdn.net/yyt8yyt8/article/details/8020154 1. Linux的热插拔事件由kernel通过中断发现(比如,USB设备插入系统 ...

  8. Task.ConfigureAwait

    public ConfiguredTaskAwaitable ConfigureAwait( bool continueOnCapturedContext ) Configures an awaite ...

  9. cxf调用WebService

    一.用CXF调用WebService的几种方式,参考: http://cxf.apache.org/docs/how-do-i-develop-a-client.html 二.JaxWsProxyFa ...

  10. vs2015编译使用GRPC

    1.获取源码:位于github上 电脑装有git的直接克隆,未装git下载压缩包也可以 git clone  https://github.com/grpc/grpc.git cd grpc git ...