Gym - 100637J

Posted spongeb0b

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gym - 100637J相关的知识,希望对你有一定的参考价值。

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?≤?1061?≤?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就行了。具体看代码。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cmath>
 4 using namespace std;
 5 int a[1000000]={0};
 6 int main()
 7 {
 8     long long int p,q;
 9     cin>>p>>q;
10     int t;
11     for(int i=1;i<1000000;i++)
12     {
13         p*=i;
14         a[i]=p/q;
15         p=p%q;
16         if(p==0)
17         {
18             t=i;
19             break;
20         }
21     }
22     cout<<a[1];
23     for(int i=2;i<=t;i++)
24     cout<< <<a[i];
25     cout<<endl;
26 }

 

以上是关于Gym - 100637J的主要内容,如果未能解决你的问题,请参考以下文章

openAi-gym 名称错误

解决使用Monitor出现gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables的问题(代码

Gym 100917M Matrix, The

gym第一个程序

gym第一个程序

并行运行 openai-gym 环境