EularProject 61:Cyclical figurate numbers
来源:互联网 发布:淘宝威客平台 编辑:程序博客网 时间:2024/05/25 16:37
Andrew Zhang
Sep 4, 2017
Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae:
Triangle P3,n=n(n+1)/2 1, 3, 6, 10, 15, …
Square P4,n=n2 1, 4, 9, 16, 25, …
Pentagonal P5,n=n(3n−1)/2 1, 5, 12, 22, 35, …
Hexagonal P6,n=n(2n−1) 1, 6, 15, 28, 45, …
Heptagonal P7,n=n(5n−3)/2 1, 7, 18, 34, 55, …
Octagonal P8,n=n(3n−2) 1, 8, 21, 40, 65, …
The ordered set of three 4-digit numbers: 8128, 2882, 8281, has three interesting properties.
The set is cyclic, in that the last two digits of each number is the first two digits of the next number (including the last number with the first).
Each polygonal type: triangle (P3,127=8128), square (P4,91=8281), and pentagonal (P5,44=2882), is represented by a different number in the set.
This is the only set of 4-digit numbers with this property.
Find the sum of the only ordered set of six cyclic 4-digit numbers for which each polygonal type: triangle, square, pentagonal, hexagonal, heptagonal, and octagonal, is represented by a different number in the set.
code:
#include <vector>#include <iostream>using namespace std;vector<vector<bool>> state(6, vector<bool>(10000));vector<bool> visited(6);bool func(int prefix, int count, int &start){ int i, j; for(i = 0; i < 6; i++) { if(visited[i] == false) { for(j = prefix * 100 + 10; j < prefix * 100 + 100; j++) { if(state[i][j]) { if(count == 2) { if(j % 100 == start) { cout<< j <<endl; return true; } else { return false; } } else { visited[i] = true; if(func(j % 100, count + 1, start)) { cout << j << endl; return true; } visited[i] = false; } } } } } return false;}int main(){ int i, j; int origin; i = 1; while ((j = i * (i + 1) / 2) && (j < 10000)) { if(j > 999) state[0][j] = true; i++; } i = 1; while ((j = i * i) && (j < 10000)) { if(j > 999) state[1][j] = true; i++; } i = 1; while ((j = i * (3 * i - 1) / 2) && (j < 10000)) { if(j > 999) state[2][j] = true; i++; } i = 1; while ((j = i * (2 * i - 1)) && (j < 10000)) { if(j > 999) state[3][j] = true; i++; } i = 1; while ((j = i * (5 * i - 3) / 2) && (j < 10000)) { if(j > 999) state[4][j] = true; i++; } i = 1; while ((j = i * (3 * i - 2)) && (j < 10000)) { if(j > 999) state[5][j] = true; i++; } for(j = 1000; j < 10000; j++) { int prefix = j % 100; if(prefix > 9) { for(i = 0; i < 6; i++) { if(state[i][j]) { visited[i] = true; origin = j / 100; if(func(j % 100, 1, origin)) { cout << j << endl; cout<<"==============="<<endl; } visited[i] = false; } } } } cout<<"search finished"<<endl; system("pause");}
- EularProject 61:Cyclical figurate numbers
- Project Euler:Problem 61 Cyclical figurate numbers
- Cyclical Quest CF235C
- CF235C Cyclical Quest
- Cyclical Quest CodeForces
- [CF235C] Cyclical Quest
- EularProject 35:循环素数
- EularProject 99:Largest exponential
- Eularproject 76:Counting summations
- EularProject 71:Ordered fractions
- EularProject 66:Diophantine equation
- EularProject 85:Counting rectangles
- Codeforces 235C Cyclical Quest
- codeforces 235C Cyclical Quest
- CF 235C Cyclical Quest
- Codeforces 235C : Cyclical Quest
- EularProject 64: 平方根的周期性
- EularProject 19: 星期日的个数
- 顺序栈的基本操作
- camera shake 相机抖动
- 配置IP & 虚拟机网络排查
- 我的编码习惯
- 多线程
- EularProject 61:Cyclical figurate numbers
- 【Linux】信号机制
- ubuntu14.04+kinectv1+orbslam2安装
- React Native 控件封装
- 训练集、验证集和测试集的意义
- pandas 使用apply同时处理两列数据
- 所有设备都不安全 只要连WiFi 就会被入侵
- python乱码解决以及sys编码格式
- 【GitHub】使用Eclipse提交代码到github