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 ≤ 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的更多相关文章
- CF Gym 100637J Superfactorial numeral system (构造)
题意:给一个式子,ak,k>2时,0<=ak<k:ai都是整数,给你p,q让你求一组ak. 题解:构造,每次除掉q取整得到ai,然后减一减 #include<cstdio> ...
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
随机推荐
- 白盒测试实践-day03
一.任务进展情况 完成了基本的测试过程,下一步整理文档. 二.存在的问题 对于JUnit测试,对测试系统还不是太了解,导致测试脚本无法写. 三.解决方法 熟悉测试系统的结构,上网搜集资料.
- qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
执行 qmake -v 出现错误:qmake: could not exec ‘/usr/lib/x86_64-linux-gnu/qt4/bin/qmake’: No such file or di ...
- BZOJ 1053 - 反素数ant - [数论+DFS][HAOI2007]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 题解: 可以证明,$1 \sim N$ 中最大的反质数,就是 $1 \sim N$ ...
- oracle DML语句 事务的定义与特点
1.insert into (插入数据) insert in to 表名(列表1,列表2) values(要插入的数据1,数据2); or insert into 表名 values(数据 ...
- NABCD---生活日历
本软件的主体为日历.如今人们的生活趋于现代化,大家主要通过手机来查看日期,但我们每一天都有想要做或未完成的事情,也存在对自己有特殊意义的日子.每天人们都会有或大或小的支出与收入,想要系统的记录这些支出 ...
- 从手机中提取boot.img
测试环境:nexus 5,android 6.0 怕出问题可以先用TWRP备份 adb shell su cd /dev/block/platform/msm_sdcc./by-name ls -l ...
- jmeter常用插件介绍
一.下载安装及使用 下载地址:jmeter-plugins.org 安装:下载后文件为plugins-manager.jar格式,将其放入jmeter安装目录下的lib/ext目录,然后重启jmete ...
- Mybatis+Mysql逆向工程
目录结构: pom文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...
- JAVA学习笔记 (okHttp3的用法)
最近的项目中有个接口是返回文件流数据,根据我们这边一个验签的插件,我发现里面有okHttpClient提供了Call.Factory,所以就学习了下okHttp3的用法. 1.概述 okhttp是一个 ...
- Python 多进程和进程池
一,前言 进程:是程序,资源集合,进程控制块组成,是最小的资源单位 特点:就对Python而言,可以实现真正的并行效果 缺点:进程切换很容易消耗cpu资源,进程之间的通信相对线程来说比较麻烦 线程:是 ...