2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D

Problem D. Distribution in Metagonia Input file: distribution.in Output file: distribution.out Time limit: 2 seconds Memory limit: 256 megabytes There are one hundred noble families in the country of Metagonia, and each year some of these families receive several ritual cubes from the Seer of the One. The One has several rules about cube distribution: if a family receives at least one cube, every prime divisor of the number of cubes received should be either 2 or 3, moreover if one family receives a > 0 cubes and another family in the same year receives b > 0 cubes then a should not be divisible by b and vice versa. You are the Seer of the One. You know in advance how many cubes would be available for distribution for the next t years. You want to find any valid distribution of cubes for each of these years. Each year you have to distribute all cubes available for that year.

Input The first line of input file contains a single integer t — the number of years to come (1 ≤ t ≤ 1000). Each of the following t lines contains a single integer ni — the number of cubes to distribute in i-th year (1 ≤ ni ≤ 1018).

Output For each year i output two lines. The first line should contain mi — the number of families that would receive at least one cube in i-th year (1 ≤ mi ≤ 100). The second line should contain mi integers — the number of cubes received by each family. The sum of these numbers should be equal to ni .

Example

distribution.in

distribution.out

input:

4

1

2

3

10

output:

1

1

1

2

1 3

2

4 6

题意:  输入一个数n,把n拆分成多个数的和,且每个数的素因子只有2和3,数之间不能整除;

思路:  将n整除以2^t,使n变为奇数,找到3^k<=n,最大的k,则2^t*3^k为拆分后的一个数,则n-2^t*3^k必为一个偶数,再做相同的操作得到下一个拆分的数,直至n=0;

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL; vector <LL> vec;
int main()
{
//freopen("distribution.in","r",stdin);
//freopen("distribution.out","w",stdout);
int T;
LL n;
cin>>T;
for(int i=; i<T; i++)
{
vec.clear();
cin>>n;
for(int i=; ; i++)
{
if(n <= )
break;
LL tp = n, sum = ;
while(tp)
{
if(tp & )
break;
tp /= ;
sum *= ;
} while(sum <= n)
sum *= ;
sum /= ;
vec.push_back(sum);
n -= sum;
}
cout<<vec.size()<<endl;
for(int i=; i<vec.size(); i++)
cout<<vec[i]<<" ";
cout<<endl;
}
return ;
}

最新文章

  1. scala 学习之:list span 用法
  2. HDU 4811 Ball -2013 ICPC南京区域现场赛
  3. qt练习10 涂鸦板源代码
  4. MSP430的比较器
  5. 【Aho-Corasick automation 大米饼模板】
  6. 又谈T检验
  7. mysql数据库的备份和恢复
  8. 获取自定义data的几种属性
  9. 基本 TCP 的回射服务器
  10. nodeJs的Buffer操作
  11. Centos下DNS+NamedManager高可用部署方案完整记录
  12. 14. Spring Boot的 thymleaf公共页抽取
  13. POJ 1061 青蛙的约会 (扩展欧几里得算法)
  14. cocos游戏的例子(摘抄记录,非原创)
  15. 利用JQuery 来操作 ListBox和ListBox内移动
  16. Check类之duplicate declaration checking/Class name generation/Type Checking
  17. 学习笔记——并行编程Parallel
  18. 25 个常用的 Linux iptables 规则【转】
  19. Rokid开发者社区skill之【历史上的今天】
  20. 【六】tf和cgi进行联合试验,完成日志服务器

热门文章

  1. 基础才是重中之重~LazyInitializer.EnsureInitialized对属性实现化的性能优化
  2. EF架构~为BulkInsert引入SET IDENTITY_INSERT ON功能
  3. FreeMarker 学习
  4. 每天一个linux命令(35):ln 命令
  5. 处于同一个域中的两台Sql server 实例无法连接
  6. QQ左侧滑动显示之自定义属性
  7. 【原创】.NET读写Excel工具Spire.Xls使用(2)Excel文件的控制
  8. 《BI那点儿事》Microsoft 决策树算法——找出三国武将特性分布,献给广大的三国爱好者们
  9. JavaScript闭包(二)——作用
  10. 可视化工具solo show-----Processing Prefuse show