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 ...
随机推荐
- Pandora 生成 Token
生成 token 打数据到仓库 通过 api 签名工具实现 最后通过curl -XPOST -H "Content-Type: application/json" -H " ...
- CodeForces 1143A The Doors
The Doors 签到题 #include <iostream> using namespace std; int a[200005]; int main() { int n; scan ...
- 泡泡一分钟: Deep-LK for Efficient Adaptive Object Tracking
Deep-LK for Efficient Adaptive Object Tracking "链接:https://pan.baidu.com/s/1Hn-CVgiR7WV0jvaYBv5 ...
- error lnk1158 无法运行rc.exe
找到C:\Program Files (x86)\Windows Kits\8.0\bin\在运行一下rc.exe和rcdll.dll拷贝到D:\Soft\VS2015\VC\bin目录下.
- [ionic3.x开发记录]参考ionic的float-label动效,写一个项目内通用的input组件,易扩展
上图: module: import {NgModule} from "@angular/core"; import {CommonModule} from "@angu ...
- scrapy学习笔记(1)
初探scrapy,发现很多入门教程对应的网址都失效或者改变布局了,走了很多弯路.于是自己摸索做一个笔记. 环境是win10 python3.6(anaconda). 安装 pip install sc ...
- 包的初识和进阶&异常处理
包 包是一种通过使用‘.模块名’来组织python模块名称空间的方式. 1. 无论是import形式还是from...import形式,凡是在导入语句中(而不是在使用时)遇到带点的,都要第一时间提高警 ...
- Android Studio开发快速创建MVP框架插件AndroidMVP
转载:https://www.jianshu.com/p/60cd98bbc358 Android开发中,我们为了代码的解耦以及后期的维护方便,都会采用一些开发框架,常用的有MVC.MVP.MVVM. ...
- 异常处理之IIS配置加载出错
问题详情: 一台部署在海外服务器,在管理IIS过程中,出现问题 There was an error when trying to connect. Do you want > to rety ...
- jupyter notebook 动态图显示
直接在import matplotlib.pyplot as plt 后面加%matplotlib,或者%matplotlib auto就可以通过弹出窗口的形式显示图片