http://codeforces.com/gym/100801/attachments

题意:给出一个数n(1 <= n <= 1e18),将 n 拆成 m 个整数,其中 m 必须是 2^x * 3^y 的形式,并且 x 和 y 不能被彼此整除, 输出 m 并将这些整数输出。

思路:Inspired by http://blog.csdn.net/snowy_smile/article/details/49852091 。

第一步:因为要求的 m 是 2^x * 3^y 的形式,所以如果 n 可以直接被 2^x * 3^y 整除的话,即 n % (2^x * 3^y) == 0,那么就可以直接输出 n 了。如果不能被直接整除的话,我们可以先将 n 拆解成不能被 3 和 2 整除的形式,这里的话用一个 mul 记录 n 除以多少。

     while(n %  == ) {
n /= ;
mul *= ;
}
while(n % == ) {
n /= ;
mul *= ;
}
if(n == ) {
num[m++] = mul;
return ;
}

第二步:那么更重要的问题是如果 n 不能被 2 或 3 整除,同时也不为 1 时应该怎么做。因为不能被 2 整除,所以这时的 n 必定是一个奇数。那么我们可以将 n 减去 w,w = 3^y && w < n,我们所做的是将 n 拆解出一个 w(w必定为奇数),那么剩下的 n 就是一个偶数了,这个时候我们又能回到第一步进行递归求解了。因为我们拆出的 w  也是组成 n 的一部分,因此要记录下来,记录的数值是 w * mul,因为我们前面 n 除以了 一些 2 和 3 ,我们用 mul 记录下来了,因此这个时候要乘回去,所以是 w * mul。

 else {
long long x = ;
while(x * < n) {
x *= ;
}
n -= x;
num[m++] = x * mul;
solve(n, mul);
}
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
using namespace std;
typedef long long LL;
LL num[];
int m;
/*
题意:将n拆成m个数,这m个数的表示是
*/
void solve(LL n, LL mul)
{
while(n % == ) {
n /= ;
mul *= ;
}
while(n % == ) {
n /= ;
mul *= ;
}
if(n == ) {
num[m++] = mul;
return ;
} else {
long long x = ;
while(x * < n) {
x *= ;
}
n -= x;
num[m++] = x * mul;
solve(n, mul);
}
} int main()
{
freopen("distribution.in", "r", stdin);
freopen("distribution.out", "w", stdout);
int t;
cin >> t;
while(t--) {
LL n;
cin >> n;
m = ;
solve(n, );
cout << m << endl;
for(int i = ; i < m; i++) {
cout << num[i];
if(i != m-) cout << " ";
else cout << endl;
}
}
return ;
}

2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D:Distribution in Metagonia(构造)的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D】---暑假三校训练

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D Problem D. Distribution in Metagonia Input ...

  4. 模拟赛小结:2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest 2019年10月11日 15:35-20:35(Solved 8,Penalty 675 ...

  5. 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest (9/12)

    $$2015-2016\ ACM-ICPC,\ NEERC,\ Northern\ Subregional\ Contest$$ \(A.Alex\ Origami\ Squares\) 签到 //# ...

  6. ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...

  7. 2016 NEERC, Northern Subregional Contest G.Gangsters in Central City(LCA)

    G.Gangsters in Central City 题意:一棵树,节点1为根,是水源.水顺着边流至叶子.该树的每个叶子上有房子.有q个询问,一种为房子u被强盗入侵,另一种为强盗撤离房子u.对于每个 ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  9. 2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest Problem F. Format

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:1s 空间限制:512MB 题目大意: 给定一个字符串,使用%[...] ...

  10. 2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest Problem I. Integral Polygons

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个凸多边形,有一种连接两个 ...

随机推荐

  1. HDU-3839-Ancient Messages(DFS)

    Problem Description In order to understand early civilizations, archaeologists often study texts wri ...

  2. WPF - 资源收集

    原文:WPF - 资源收集 OpenExpressApp的UI现在是使用WPF,所以熟悉WPF是必须的,以下我将可能用到的一些相关内容随时记录下来,以备查阅.此篇文章将不断更新,感兴趣的可以看看,也欢 ...

  3. JS顶级对象window

    <script type="text/javascript">        var num = 100;         alert(num);       wind ...

  4. Delphi7文件操作常用函数

    1. AssignFile.Erase AssignFile procedure AssignFile(var F; FileName: string);:给文件变量连接一个外部文件名.这里需要注意的 ...

  5. Redis实现Timeline

    上回写了[使用Redis实现关注关系][1],这次说说使用Redis实现Timeline. Timeline的实现一般有推模式.拉模式.推拉结合这几种. 推模式:某人发布内容之后推送给所有粉丝,空间换 ...

  6. 关于powerdesigner中的data types说明

    原文:关于powerdesigner中的data types说明 这一堆的数据类型看着真是头大,弄个表格对照一下. Numeric data types Standard datatype DBMS- ...

  7. Android零碎知识之Style and Theme

    Android的styles资源文件中存在了我们在应用中定义的各种style,它们都是以style开始的元素,包含许多属性的集合.但我们一般般它们分为style和theme,那它们有什么区别呢? 一. ...

  8. Delphi 与 VC 共享接口和对象

    我经常会用 Delphi 写一些工具和应用,为了扩展方便,大部分都会做成插件形式. 迫于某些原因,我的插件不得不用其他开发工具来完成,比如 VC. 于是有个大问题需要解决:如何让 D 和 VC 互相通 ...

  9. Cookie概述与应用

    一.概述 Cookie是Web服务器保存在客户端的一系列文本信息 典型应用一:判断注册用户是否已经登录网站. 典型应用二:"购物车"的处理. Cookie的作用:     对特定对 ...

  10. 转载几篇文章URL

    读了百伯在线Jobbole的几篇文章,转给需要的朋友.如下: 产品小设计大体验:http://blog.jobbole.com/39593/ 苹果是一家有工程师的设计公司:Google是一家有设计师的 ...