zoukankan      html  css  js  c++  java
  • Gym

    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 }
  • 相关阅读:
    tsm 存放磁带到带库
    tsm 切记
    添加路由时啥时候是dev啥时候是gw
    网卡上绑定多个IP地址
    更改本地环回地址引发的血案
    自学网络 arp_ignore/arp_announce
    do_try_to_free_pages
    如何用ssh实现端口的映射
    显示系统中所有的socket信息
    ifstat查看网络流量的原理
  • 原文地址:https://www.cnblogs.com/spongeb0b/p/9350163.html
Copyright © 2011-2022 走看看