题意:

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. 导致“mysql has gone away”的两种情况

    导致“mysql has gone away”的两种情况 By Cruise 1.  wait_timeout参数 在开发代理server时, 我使用了jdbc连接数据库,并采用长连接的方式连接数据库 ...

  2. Android--真机调试程序方法

    方法例如以下: (1)手机通过数据线连接到手机上. (2)在手机中设置:设置-->应用程序-->开发-->USB调试 (3)在CMD中測试一下.连接是否正常,CMD中命令例如以下: ...

  3. C++开发人脸性别识别教程(19)——界面美化

    在这篇博文中将完毕<C++开发人脸性别识别>的收尾工作.主要内容分为两部分:加入视频暂定功能.界面规范化. 一 视频暂停功能 严格来说这个视频暂定功能算是视频人脸性别识别的一个遗留问题,本 ...

  4. 安卓欢迎界面和activity之间的跳转问题

    使用安卓的UI界面,就不得不了解activity,由于actvity就像是一个form表单一样,全部的UI都呈如今这里,他能够承载全部的UI控件. INtent就是一个中继站一样.他负责组件之间的沟通 ...

  5. VIM中括号的自动补全与删除

    先放来源 http://oldj.net/article/vim-parenthesis/ 很多现代 IDE 都有自动补全配对括号的功能,比如输入了左括号“(”,IDE 就自动在后面添加一个对应的右括 ...

  6. Linq的Except

    https://msdn.microsoft.com/en-us/library/bb300779(v=vs.100).aspx , , , }; , , , }; var list = list1. ...

  7. gcc 4.8安装

    suse的安装参考:http://blog.csdn.net/cloudskyfhx/article/details/17660607 有些错误处理见本文黄色部分 CentOS 6.4 编译安装 gc ...

  8. HTML5动态时钟

    实现效果 源码可以去github下载 地址:https://github.com/feifeiliu/jsBlock 参考:慕课网动态时钟

  9. 应用MVP模式对遗留代码进行重构

    AV(Autonomous View)自治视图 在面向终端用户的应用中,都需要一个可视化的UI来与用户交互.这个UI称为View视图. 在早期,我们习惯将所有前台的逻辑,与视图揉在一起,称为AV自治视 ...

  10. IE浏览器缓存导致Ajax请求失败

    在IE浏览器中通过Ajax请求后台的数据,如果Page请求是postback类型的,可能会导致Ajax请求失败的问题 我们都知道ajax能提高页面载入的速度主要的原因是通过ajax减少了重复数据的载入 ...