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. Android开发中常见的设计模式

    对于开发人员来说,设计模式有时候就是一道坎,但是设计模式又非常有用,过了这道坎,它可以让你水平提高一个档次.而在android开发中,必要的了解一些设计模式又是非常有必要的.对于想系统的学习设计模式的 ...

  2. Android学习笔记一

    一.eclipse中的十大快捷键: 1. ctrl+shift+r:打开资源 这可能是所有快捷键组合中最省时间的了.这组快捷键可以让你打开你的工作区中任何一个文件,而你只需要按下文件名或mask名中的 ...

  3. [Everyday Mathematics]20150202

    设 $f:\bbR^2\to \bbR$ 为连续函数, 且满足条件 $$\bex f(x+1,y)=f(x,y+1)=f(x,y),\quad\forall\ (x,y)\in \bbR^2. \ee ...

  4. Apache OFBiz 学习笔记 之 服务引擎 二

    加载服务定义文件   ofbiz-component.xml:所有的服务定义文件在每个组件的ofbi-component.xml文件中   加载服务定义 例:framework/common/ofbi ...

  5. IOS init initWith 等相关集中

    1.initWithCoder    当一个view从nib初始化的时候,会调用这个函数.  用keyedArchiver序列化一个类的实力,后面用keyedUnArchiver拿回来的时候会调用到 ...

  6. C#复习反射

    反射中常用方法: //获取对象类型 One one = new One(); Type t = one.GetType(); //动态加载 Assembly a = Assembly.LoadFile ...

  7. MVC3.0在各个版本IIS中的部署

    概述: 最近在做一个MVC 3的项目,在部署服务器时破费了一番功夫,特将过程整理下来,希望可以帮到大家! 本文主要介绍在IIS5.1.IIS6.0.IIS7.5中安装配置MVC 3的具体办法! 正文: ...

  8. bzoj 2599 [IOI2011]Race (点分治)

    [题意] 问树中长为k的路径中包含边数最少的路径所包含的边数. [思路] 统计经过根的路径.假设当前枚举到根的第S个子树,若x属于S子树,则有: ans<-dep[x]+min{ dep[y] ...

  9. matlab中图像处理常见用法

    一. 读写图像文件 1. imread imread函数用于读入各种图像文件,如:a=imread('e:/w01.tif') 注:计算机E盘上要有w01相应的.tif文件. 2. imwrite i ...

  10. (转)Http协议经典详解

    转自:http://blog.csdn.net/gueter/archive/2007/03/08/1524447.aspx Author :Jeffrey 引言 HTTP 是一个属于应用层的面向对象 ...