URAL2047 Maths (暴力打表 递推)
来源:互联网 发布:淘宝最大的浏览单平台 编辑:程序博客网 时间:2024/05/18 02:18
2047. Maths
Time limit: 1.0 second
Memory limit: 64 MB
Android Vasya attends Maths classes. His group started to study the number theory recently. The teacher gave them several tasks as a homework. One of them is as follows.
There is an integer n. The problem is to find a sequence of integers
Input
The only line contains an integer
Output
If there is no such sequence output
Sample
input
3
output
1 3 4
题意
输入一个
题解
首先暴力打个表,看看按照要求能够造出的最长的序列是多少,发现可以构造出长度为
打表代码:
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <stack>using namespace std;int num[30000005];int MAX = 100000000;int dfs(int n, int sum){ if (n == 100000) { MAX = min(MAX, sum); return 1; } for (int i = 1; i <= 300; i++) { if (sum + i>30000005) return 0; if (num[sum + i] == i&&dfs(n + 1, sum + i)) return 1; } return 0;}int main(){ memset(num, 0, sizeof num); for (int i = 1; i <= 30000005; i++) { for (int j = i; j <= 30000005; j += i) num[j]++; } for (int i = 1; i <= 300; i++) { dfs(1, i); } printf("%d\n", MAX); getchar(); return 0;}
AC代码:
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <stack>using namespace std;int num[1586336];int ans[100005];int n;int main(){ memset(num,0,sizeof num); for(int i=1;i<=1586335;i++) { for(int j=i;j<=1586335;j+=i) num[j]++; } int sum=1586335; for(int i=100000;i>0;i--) { ans[i]=num[sum]; sum-=num[sum]; } scanf("%d",&n); for(int i=1;i<=n;i++) printf("%d\n",ans[i]); return 0;}
- URAL2047 Maths (暴力打表 递推)
- Burger - UVa 557 滚动数组 暴力 递推 打表
- hrbust 1375 The Active Leyni【暴力打表+递推+矩阵快速幂】
- hdu2069 暴力打表
- HDU2089 暴力打表
- POJ 2042 暴力打表
- hdu 1331 (暴力打表)
- Prime Time 暴力打表
- hdu 2085 暴力打表
- hdu 1165 Eddy's research II(递推+打表)
- HDU 5382 GCD?LCM! (递推公式 + 打表)
- Tiling 2506 (打表+大数+递推)
- HDU 2041 超级楼梯(递推+打表)
- HDU 2044 一只小蜜蜂...(递推+打表)
- HDU 2046 骨牌铺方格(递推+打表)
- Codeforces Round #269 (Div. 2) C 递推+打表
- 2067 小兔的棋盘 递推+打表
- hdu 1041 打表:递推+大数 模板
- HDU2647 Reward 拓扑排序
- 在代码中获取ApplicationContext实例
- Eclipse的下没有Android sdk and avd manager
- Unity3D 中 点乘和叉乘的应用
- MyBatis魔法堂:Insert操作详解(返回主键、批量插入)
- URAL2047 Maths (暴力打表 递推)
- SpringMVC框架搭建的几个核心配置
- APIController原型
- 二分图匹配模板
- 社説 20150811 日航機墜落30年 安全運航への誓いを新たに
- 如何找出好用的PDF转换器
- 自定义控件的属性attr.xml,declare-styleable,TypedArray
- 【面经】人人,金山西山居,腾讯互娱,微信,网易游戏offer及面经
- backbone.js快速入门(四)