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. px,em,rem的区别与用法

    别人总结的.个人觉得特别的好: http://www.w3cplus.com/css/when-to-use-em-vs-rem.html

  2. PPT领取 | 70+数据科学、架构演进等最佳实践限时放送

    上世纪1950年人工智能被提出,直至2016年AlphaGo战胜世界围棋冠军李世石后,人工智能迅速引起了全球的瞩目,并推动起全球科技的浪潮.自动驾驶.人脸识别.语音交互技术等“一拥而上”,众多AI科技 ...

  3. .net不同集合类型及使用场合

    1.Dictionary-相当于字典[可以通过过索引(hash值)速添加.删除.查找]:如果需要非常快地添加.删除和查找项目,而且不关心集合中项目的顺序,那么首先应该考虑使用 System.Colle ...

  4. oracle 安装介绍

    oracle 分为客户端和服务器 全局数据库是 实例名通常就是所说的服务,就是说数据库和操作系统之间的交互用的是数据库实例名 导入 sql文件 @路径    例如@d:/my.sql [oracle@ ...

  5. spring mvc 总结

    依赖包 <!-- spring依赖 --> <dependency> <groupId>org.springframework</groupId> &l ...

  6. Service Mesh 数据平面 SOFAMosn

    https://mp.weixin.qq.com/s/DJ_IeDswGGFQiWqJ75pmig 开源 | Service Mesh 数据平面 SOFAMosn 深层揭秘 朵晓东 蚂蚁金服科技 20 ...

  7. 【转载】Fiddler工具使用介绍(一)

    原文https://www.cnblogs.com/miantest/p/7289694.html(一) https://www.cnblogs.com/miantest/p/7290176.html ...

  8. 多线程之Lock的基本介绍

    基本介绍 java.util.concurrent.locks是java1.5之后出现的一种锁实现方式,是一个接口.但是在这之前已经有一个同步机制的实现就是synchronized关键字,那为什么还要 ...

  9. mysql 日期 字符串

    Mysql 中字符串转时间跟Oracle略不同,函数为 str_to_date 应注意的是里面的大小写 如下: MySQL内置函数,在mysql里面利用str_to_date()把字符串转换为日期. ...

  10. Python 多线程和线程池

    一,前言 进程:是程序,资源集合,进程控制块组成,是最小的资源单位 特点:就对Python而言,可以实现真正的并行效果 缺点:进程切换很容易消耗cpu资源,进程之间的通信相对线程来说比较麻烦 线程:是 ...