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 ...
随机推荐
- 7、vue-awesome-swiper页面跳转
<template> <swiper :options='swiperOption' ref="mySwiper" class='swiper-container ...
- 中文乱码总结之JSP乱码
一.JSP中文乱码问题 JSP页面的汉字显示为乱码,而英文和阿拉伯数字正常. 二.原因 汉字编码时用的字符集 与解码用的字符集不一致:所有的字符集都兼容ASCII码,所以英文.数字不存在乱码. 编号 ...
- servlet 拦截器 (filter)
使用: 创建一个类实现javax.servlet.Filter接口,并重写接口中所有的方法: 在web.xml配置所需要拦截的请求. 过程说明: 1>在应用启动的时候就进行装载Filter类(与 ...
- String工具类2
1:比较字符串 public static void main(String[] args) { // String去创建对象有多种方式 // 方式1 直接字面值赋值 String s = " ...
- oo第三次总结
一.(1)规格化设计的大致发展历史 20世纪60年代,随着大容量.高速度的计算机出现,以及大量语言的新增和软件的不可靠,爆发了所谓的“软件危机”.而针对这个问题,人们提出了规格化设计的解决方法.通过把 ...
- 【大数据和云计算技术社区】分库分表技术演进&最佳实践笔记
1.需求背景 移动互联网时代,海量的用户每天产生海量的数量,这些海量数据远不是一张表能Hold住的.比如 用户表:支付宝8亿,微信10亿.CITIC对公140万,对私8700万. 订单表:美团每天几千 ...
- Java集合List、Set、Map
集合是 java 基础中非常重要的一部分,同样也是 Java 面试中很重要的一个知识点.所以,给王小整理了这篇关于集合的文章. 1.接口继承关系以及实现 集合类存放于 Java.util 包中,主要有 ...
- weblogic的基础安装
安装java环境 不能使用centos自带的openjdk 必须使用源码安装 把下载的jdk-8u181-linux-x64.tar 解压到 /usr/src目录下 tar zxvf jd ...
- Hello greenDAO(SQLite)
一.配置Gradle Scripts: 1.1.build.gradle(Project:*****) buildscript { repositories { google() jcenter() ...
- 2018DDCTF misc1
一.题目: (╯°□°)╯︵ ┻━┻ d4e8e1f4a0f7e1f3a0e6e1f3f4a1a0d4e8e5a0e6ece1e7a0e9f3baa0c4c4c3d4c6fbb9e1e6b3e3b9e ...