Maths
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87157#problem/B

Description

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 a1, …, an such that for any k from 2 to n the sum a1 + … + ak has exactly ak different positive divisors. Help Vasya to cope with this task.
 

Input

The only line contains an integer n (2 ≤ n ≤ 100 000).
 

Output

If there is no such sequence output “Impossible”. Otherwise output space-separated integers a1, …, an (1 ≤ ai ≤ 300).

Sample Input

3

Sample Output

1 3 4

HINT

题意

让你构造n个数,要求a1+……+ak的和的因子数恰好为ak

题解

假设我们已经构造出了ak,且前缀和sum已知,那么ak-1=sum-ak,这个是显然的结论

于是我们直接打表打出来100000位就好了,然后把sum求出来,然后前面直接递推就好了

代码:

打表程序:

#pragma comment(linker, "/STACK:102400000,102400000")

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int cnt[*];
vector<int> Q;
int flag=;
int n;
void dfs(int N,int sum,int z)
{
if(flag)
return;
if(sum+z>*)
return;
if(N>&&cnt[sum]!=z)
return;
if(N==n)
{
printf("%d",Q[]);
for(int i=;i<Q.size();i++)
printf(" %d",Q[i]);
printf("\n");
cout<<sum<<endl;
flag=;
return;
}
for(int i=;i<=;i++)
{
Q.push_back(i);
dfs(N+,sum+i,i);
Q.erase(Q.end()-);
} }
int main()
{
freopen("1.out","w",stdout);
for(int i=;i<=*;i++)
{
for(int j=i;j<*;j+=i)
{
cnt[j]++;
}
}
n=read();
Q.clear();
flag=;
for(int i=;i<=;i++)
{
Q.push_back(i);
dfs(,i,i);
Q.erase(Q.end()-);
}
if(flag==)
printf("Impossible\n");
}

AC程序:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 20001
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//**************************************************************************************
const int N=;
int cnt[N];
int a[N],sum=;
vector<int> Q;
int flag=;
int n;
int tot;
int main()
{
for(int i=;i<N;i++)
{
for(int j=i;j<N;j+=i)
cnt[j]++;
}
for(int p=,i=;i>;p-=cnt[p],i--)
{
a[i]=cnt[p];
sum+=a[i];
}
n=read();
for(int i=;i<n;i++) printf("%d ",a[i]);
printf("%d\n",a[n]);
}

URAL 2047 Maths 打表 递推的更多相关文章

  1. poj1338 Ugly Numbers 打表, 递推

    题意:一个数的质因子能是2, 3, 5, 那么这个数是丑数. 思路: 打表或者递推. 打表: 若该数为丑数,那么一定能被2 或者3, 或者5 整除, 除完之后则为1. #include <ios ...

  2. URAL 1260 Nudnik Photographer(递推)

    题目链接 题意 : 给你1到n这n个数,排成一排,然后1放在左边最开始,剩下的数进行排列,要求排列出来的数列必须满足任何两个相邻的数之间的差不能超过2,问你有多少种排列 思路 : 对于dp[n], n ...

  3. URAL 2047 Maths (数学)

    对于一个数来说,它的除数是确定的,那么它的前驱也是确定的,而起点只能是1或2,所以只要类似筛法先预处理出每个数的除数个数 ,然后递推出每个数往前的延伸的链长,更新最大长度,记录对应数字.找到maxn以 ...

  4. 递推DP URAL 1017 Staircases

    题目传送门 /* 题意:给n块砖头,问能组成多少个楼梯,楼梯至少两层,且每层至少一块砖头,层与层之间数目不能相等! 递推DP:dp[i][j] 表示总共i块砖头,最后一列的砖头数是j块的方案数 状态转 ...

  5. 递推DP URAL 1260 Nudnik Photographer

    题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> ...

  6. 递推DP URAL 1353 Milliard Vasya's Function

    题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...

  7. 递推DP URAL 1119 Metro

    题目传送门 /* 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 递推DP:仿照JayYe,处理的很巧妙,学习:) 好 ...

  8. 【THUSC2017】【LOJ2981】如果奇迹有颜色 DP BM 打表 线性递推

    题目大意 有一个 \(n\) 个点的环,你要用 \(m\) 中颜色染这 \(n\) 个点. 要求连续 \(m\) 个点的颜色不能是 $1 \sim m $ 的排列. 两种环相同当且仅当这两个环可以在旋 ...

  9. jzoj5195. 【NOIP2017提高组模拟7.3】A(递推,打表)

    Description

随机推荐

  1. IT经理,你在这个位置吗

    事实上我离这个位置还远着,或者说它可能并不是我以后的方向,但是作为一个码农,这个发展路线还是需要了解的.主要的还是喜欢下面这个图,因为里面我的发展方向,有我的目标. 对 于一个IT从业者,让你谋得工作 ...

  2. T-SQL 常用语句学习

    一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server ---  ...

  3. Linux基本命令(3)文件备份和压缩命令

    文件备份和压缩命令 在Linux中,常用的文件压缩工具有gzip.bzip2.zip.bzip2是最理想的压缩工具,它提供了最大限度的压缩.zip兼容性好,Windows也支持. 命令 功能 bzip ...

  4. Asp.net TextBox常规输入验证

    Asp.net TextBox只能输入数字<asp:textbox id="TextBox1" onkeyup="if(isNaN(value))execComma ...

  5. ASP.NET常用加密解密方法

    ASP.NET常用加密解密方法 一.MD5加密解密 1.加密 C# 代码           public static string ToMd5(string clearString)        ...

  6. 找出图像I的代数中心

    function centerGPos = cenP(I ) %cenP finds the core of the PSF % [row, col] = find(I > ); minRow ...

  7. LeetCode题解——4Sum

    题目: 给定一个数组,找出其中和为0的所有4个数组合,每个组合内的4个数非递降. 解法: ①先排序,然后利用4个指针,前两个遍历,后两个在第二个指针之后的部分里夹逼,时间O(N3). ②或者利用一个哈 ...

  8. 第四章:更多的bash shell命令

    第四章:更多的bash shell命令 监测程序 ps (其他ps内容见#1 ) Unix风格的ps命令参数 参数 描述 -A 显示所有进程 -N 显示与指定参数不符的所有进程 -a 显示除控制进程( ...

  9. Hadoop上路-02_Hadoop FS Shell

    一.上传文件/目录 1)put 从本地文件系统中复制N个源路径到目标文件系统. 2)copyFromLocal 源路径须是一个本地文件. 二.下载文件/目录 1)get 复制文件到本地文件系统. 2) ...

  10. es 的集群状态

    es的集群状态一共有三种 : green yellow red 状态是基于 碎片的 等级进行划分的 .