On the most perfect of all planets i1c5l various numeral systems are being used during programming contests. In the second division they use a superfactorial numeral system. In this system any positive integer is presented as a linear combination of numbers converse to factorials:

Here a1 is non-negative integer, and integers ak for k ≥ 2 satisfy 0 ≤ ak < k. The nonsignificant zeros in the tail of the superfactorial number designation  are rejected. The task is to find out how the rational number  is presented in the superfactorial numeral system.

Input

Single line contains two space-separated integers p and q (1 ≤ p ≤ 106, 1 ≤ q ≤ 106).

Output

Single line should contain a sequence of space-separated integers a1, a2, ..., an, forming a number designation  in the superfactorial numeral system. If several solution exist, output any of them.

题意:给你p和q,叫你找出所有ai使得等式成立

思路:因为有阶乘所以不能暴力求解,可以先把q乘过去,就变成了p=a1*q+a2*q/2!+...,很明显此时常数项a1=p/q,然后减去该项,将等式两边同时*2,此时a2就变成了常数项,求出a2再减掉,两边同时*3,a3也变成了常数项,以此类推。所以只要枚举n就行了。具体看代码。

 #include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[]={};
int main()
{
long long int p,q;
cin>>p>>q;
int t;
for(int i=;i<;i++)
{
p*=i;
a[i]=p/q;
p=p%q;
if(p==)
{
t=i;
break;
}
}
cout<<a[];
for(int i=;i<=t;i++)
cout<<' '<<a[i];
cout<<endl;
}

Gym - 100637J的更多相关文章

  1. CF Gym 100637J Superfactorial numeral system (构造)

    题意:给一个式子,ak,k>2时,0<=ak<k:ai都是整数,给你p,q让你求一组ak. 题解:构造,每次除掉q取整得到ai,然后减一减 #include<cstdio> ...

  2. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  3. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  4. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  6. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  7. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  8. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  9. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

随机推荐

  1. Selenium 3----鼠标、键盘操作常用方法

    [鼠标] 在 WebDriver 中, 关于鼠标操作的方法封装在 ActionChains 类中. ActionChains 类提供了鼠标操作的常用方法: perform(): 执行所有 Action ...

  2. linux用户添加组

    usermod -G groupname username (这种会把用户从其他组中去掉,只属于该组)如:usermod -G git git (git只属于git组) usermod -a -G g ...

  3. Ubuntu-1604-LTS在虚拟机设置分辨率

    在虚拟机中安装ubuntu系统时,有时系统的界面并不同虚拟机展示的匹配,需要我们进行调整.不用那么多废话,直接看图:

  4. zookeeper 日志输出到指定文件夹

    最近在研究Zookeeper Storm Kafka, 顺便在本地搭了一套集群, 遇到了Zookeeper日志问题输出路径的问题, 发现zookeeper设置log4j.properties不能解决日 ...

  5. [daily][archlinux] TODO LIST

    reminder: https://wikemacs.org/wiki/Buffer_management TO READ: https://www.kernel.org/doc/htmldocs/k ...

  6. hydra用法

    三.Syntax # hydra [[[-l LOGIN|-L FILE] [-p PASS|-P FILE]] | [-C FILE]] [-e ns] [-o FILE] [-t TASKS] [ ...

  7. 移动端适配--flexible.js

    引言: H5适配一直是一个比较普遍的问题,很多文章都会讲,最近开发了一个H5的项目使用了一下淘宝的 flexible.js,写一篇文章自己总结一下. 一.背景介绍: Flexible.js是淘宝公开的 ...

  8. ADB——模拟手机按键输入

    基本命令 adb 模拟按键输入的命令主要通过 input 进行 Usage: input [<source>] <command> [<arg>...] The s ...

  9. python基础之 time,datetime,collections

    1.time模块 python中的time和datetime模块是时间方面的模块 time模块中时间表现的格式主要有三种: 1.timestamp:时间戳,时间戳表示的是从1970年1月1日00:00 ...

  10. BIML 101 - ETL数据清洗 系列 - BIML 快速入门教程 - 连接数据库执行SQL语句

    BIML 101 - BIML 快速入门教程 第一节 连接数据库执行SQL语句 本小节将用BIML建一个简单的可以执行的包. 新建一个biml文件,贴入下面的代码 1 <Biml xmlns=& ...