博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2591 Set Definition(递推)
阅读量:2232 次
发布时间:2019-05-09

本文共 1194 字,大约阅读时间需要 3 分钟。

转载请注明出处:

题目链接:

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:
 
----------------------------------------------------------------------------------------------------------------------------------------------------------

Description

Set S is defined as follows: 
(1) 1 is in S; 
(2) If x is in S, then 2x + 1 and 3x + 1 are also in S; 
(3) No other element belongs to S. 
Find the N-th element of set S, if we sort the elements in S by increasing order.

Input

Input will contain several test cases; each contains a single positive integer N (1 <= N <= 10000000), which has been described above.

Output

For each test case, output the corresponding element in S.

Sample Input

100254

Sample Output

4181461

Source

,Static

代码例如以下:

#include 
using namespace std;int a[10000017];int main(){ int i, two = 1, three = 1; a[1] = 1; for(i = 2; i <= 10000000; i++) { a[i] = min(a[two]*2+1,a[three]*3+1); if(a[i] == a[two]*2+1) two++; if(a[i] == a[three]*3+1) three++; } int n; while(cin >> n) { cout<
<

转载于:https://www.cnblogs.com/ljbguanli/p/6887985.html

你可能感兴趣的文章
阿里云《云原生》公开课笔记 第八章 应用配置管理
查看>>
阿里云《云原生》公开课笔记 第九章 应用存储和持久化数据卷:核心知识
查看>>
linux系统 阿里云源
查看>>
国内外helm源记录
查看>>
牛客网题目1:最大数
查看>>
散落人间知识点记录one
查看>>
Leetcode C++ 随手刷 547.朋友圈
查看>>
手抄笔记:深入理解linux内核-1
查看>>
内存堆与栈
查看>>
Leetcode C++《每日一题》20200621 124.二叉树的最大路径和
查看>>
Leetcode C++《每日一题》20200622 面试题 16.18. 模式匹配
查看>>
Leetcode C++《每日一题》20200625 139. 单词拆分
查看>>
Leetcode C++《每日一题》20200626 338. 比特位计数
查看>>
Leetcode C++ 《拓扑排序-1》20200626 207.课程表
查看>>
Go语言学习Part1:包、变量和函数
查看>>
Go语言学习Part2:流程控制语句:for、if、else、switch 和 defer
查看>>
Go语言学习Part3:struct、slice和映射
查看>>
Go语言学习Part4-1:方法和接口
查看>>
Leetcode Go 《精选TOP面试题》20200628 69.x的平方根
查看>>
leetcode 130. Surrounded Regions
查看>>