XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative
题目:Problem A. Arithmetic Derivative
Input file: standard input
Output file: standard input
Time limit: 1 second
Memory limit: 256 mebibytes
Lets define an arithmetic derivative:
• if p = 1 then p0 = 0;
• if p is prime then p0 = 1;
• if p is not prime then n0 = (a · b)0 = a0 · b + a · b0.
For example, 60 = (2 · 3)0 = 20 · 3 + 2 · 30 = 5.
Given positive integers k and r, find all positive integers n such as n ≤ r and n0 = k · n.
Input
Input contains two integers k and r (1 ≤ k ≤ 30; 1 ≤ r ≤ 2 · 1018).
Output
If there are no such numbers, print 0. Otherwise in first line print m — number of positive integers n does
not exceeding r, for which n0 = k · n. Second line then must contain those m integers in ascending order.
Examples
| standard input | standard input |
| 1 100 | 2 4 27 |
| 1 2 | 0 |
#include<iostream>
#include <vector>
#include <algorithm>
using namespace std; long long num[]={,,,,,,}; long long k,r,ans; vector<long long> v; void dfs(int x,long long nownum,long long r)
{
if(x>)
{
if(r)
return ;
if(nownum<=k)
{
ans++;
v.push_back(nownum);
}
return ;
}
long long nn=;
for(int i=;i<=r;i++)
{
if(i==)
dfs(x+,nownum,r);
else
{
if(k/nn<num[x])
break;
else
nn*=num[x];
if(k/nownum<nn)
break;
dfs(x+,nownum*nn,r-i);
}
}
return ;
} int main()
{
cin>>r>>k;
if(r==)
{
for(int i=;i<=;i++)
if(num[i]<=k)
ans++;
cout<<ans<<endl;
for(int i=;i<=ans;i++)
cout<<num[i]<<' ';
return ;
}
dfs(,,r);
cout<<ans<<endl;
sort(v.begin(),v.end());
for(int i=;i<ans;i++)
cout<<v[i]<<' ';
return ;
}
XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative的更多相关文章
- 【找规律】【DFS】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative
假设一个数有n个质因子a1,a2,..,an,那么n'=Σ(a1*a2*...*an)/ai. 打个表出来,发现一个数x,如果x'=Kx,那么x一定由K个“基础因子”组成. 这些基础因子是2^2,3^ ...
- 【二分】【字符串哈希】【二分图最大匹配】【最大流】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem I. Minimum Prefix
给你n个字符串,问你最小的长度的前缀,使得每个字符串任意循环滑动之后,这些前缀都两两不同. 二分答案mid之后,将每个字符串长度为mid的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选 ...
- XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures
题目:Problem D. Clones and TreasuresInput file: standard inputOutput file: standard outputTime limit: ...
- 【二分图】【并查集】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel
给你一个网格(n<=2000,m<=2000),有一些炸弹,你可以选择一个空的位置,再放一个炸弹并将其引爆,一个炸弹爆炸后,其所在行和列的所有炸弹都会爆炸,连锁反应. 问你所能引爆的最多炸 ...
- 【动态规划】【滚动数组】【bitset】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal
有两辆车,容量都为K,有n(10w)个人被划分成m(2k)组,依次上车,每个人上车花一秒.每一组的人都要上同一辆车,一辆车的等待时间是其停留时间*其载的人数,问最小的两辆车的总等待时间. 是f(i,j ...
- 【枚举】【最小表示法】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game
给你一个n*m的字符矩阵,将横向(或纵向)全部裂开,然后以任意顺序首尾相接,然后再从中间任意位置切开,问你能构成的字典序最大的字符串. 以横向切开为例,纵向类似. 将所有横排从大到小排序,枚举最后切开 ...
- 【推导】【构造】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem E. Space Tourists
给你n,K,问你要选出最少几个长度为2的K进制数,才能让所有的n位K进制数删除n-2个元素后,所剩余的长度为2的子序列至少有一个是你所选定的. 如果n>K,那么根据抽屉原理,对于所有n位K进制数 ...
- 【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures
给你一行房间,有的是隐身药水,有的是守卫,有的是金币. 你可以任选起点,向右走,每经过一个药水或金币就拿走,每经过一个守卫必须消耗1个药水,问你最多得几个金币. 药水看成左括号,守卫看成右括号, 就从 ...
- XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game
题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondM ...
随机推荐
- C# 直接调用非托管代码的方法
C# 代码有以下两种可以直接调用非托管代码的方法: 直接调用从 DLL 导出的函数. 调用 COM 对象上的接口方法. 对于这两种技术,都必须向 C# 编译器提供非托管函数的声明,并且还可能需要向 C ...
- malloc free, new delete 的异同点
相同点: 都可以动态的申请并释放内存 不同点: 1. 用法不同 <1> malloc 函数为 void* malloc(size_t size), 用于申请一块长度为 size 字节的内存 ...
- sql中where以后and和or的用法
SELECT * FROM NOTICE WHERE 1 = 1 AND (Z_STATUS = 1 AND RELEASE_DEPT_ID = '-1' AND IS_ISSUE = 1 OR IN ...
- jenkins配置邮件报警
author:headsen chen date: 2018-05-15 13:49:21 在jerkins的主配置页面上: 注意:不用 安装什么报警邮件的插件.直接配置就可以了. 系统管理 --- ...
- Hibernate更新数据报错:a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]
使用hibernate更新数据时,报错 Struts has detected an unhandled exception: Messages: a different object with th ...
- System.getProperty()方法大全 (转载)
System.out.println("java版本号:" + System.getProperty("java.version")); // java版本号S ...
- nginx提高加载静态文件速度
1.本来对于静态网页,我们不需要放在应用容器中,原因一时由于应用服务器是用来解析动态网页的,针对静态网页本来就性能不高,而且还会占用应用容器的资源,所以我们专门使用nginx用来解析静态网页. ...
- 在Windows上手动安装php开发环境
安装MySQL 使用官方提供提供的安装包一键安装即可. 打开 mysql,选择Windows,MSI Installer点击下载.附:最新版mysql5.7.18下载地址 点击installer安装, ...
- Go语言 关键字:defer
defer和go一样都是Go语言提供的关键字.defer用于资源的释放,会在函数返回之前进行调用.一般采用如下模式: f,err := os.Open(filename) if err != nil ...
- NSArray最简单的倒序
NSArray里有 sortedArrayUsingSelector:等排序的方法,但是最简单的倒序排列的方法如下: NSArray *deArray = [[keyArrays reverseObj ...