Kattis之旅——Factovisors
0! = 1
n! = n * (n-1)! (n > 0)
We say that a divides b if there exists an integer k such that
k*a = b
Input
Output
Sample Input
6 9
6 27
20 10000
20 100000
1000 1009
Sample Output
9 divides 6!
27 does not divide 6!
10000 divides 20!
100000 does not divide 20!
1009 does not divide 1000!
给一个整数n和一个数m,求n的阶乘是否可以整除m。
将m分解质因数,然后对每个质因数在n中进行判断是否含有相同或者更多。
//Asimple
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = ;
ll n, m, s, res, ans, len, T, k, num;
int x, y;
int pr[maxn]; void get_pr(){
int a[maxn] = {};
len = ;
for(int i=; i<maxn; i++) {
if( a[i]== ) {
pr[len++] = i;
int j = i;
while( j < maxn ) {
a[j] = ;
j += i;
}
}
}
} bool judge(int x, int cnt) {
int c = ;
ll t = n;
while( t ) {
c += t/x;
t /= x;
}
return cnt<=c;
} void input() {
get_pr();
while( cin >> n >> m ) {
if( m == ) {
printf("%lld does not divide %lld!\n",m,n);
continue;
}
ll t = m;
bool f = true;
for(int i=; i<len && pr[i]<=m; i++) {
if( m%pr[i] == ) {
res = ;
while( m%pr[i]== ) {
res ++;
m /= pr[i];
}
f = f&&judge(pr[i], res);
}
}
if( m!= ) f = f&&judge(m, );
if( f ) printf("%lld divides %lld!\n",t,n);
else printf("%lld does not divide %lld!\n",t,n);
}
} int main(){
input();
return ;
}
Kattis之旅——Factovisors的更多相关文章
- Kattis之旅——Prime Reduction
A prime number p≥2 is an integer which is evenly divisible by only two integers: 1 and p. A composit ...
- Kattis之旅——Chinese Remainder
Input The first line of input consists of an integers T where 1≤T≤1000, the number of test cases. Th ...
- Kattis之旅——Fractional Lotion
Freddy practices various kinds of alternative medicine, such as homeopathy. This practice is based o ...
- Kattis之旅——Rational Arithmetic
Input The first line of input contains one integer, giving the number of operations to perform. Then ...
- Kattis之旅——Number Sets
You start with a sequence of consecutive integers. You want to group them into sets. You are given t ...
- Kattis之旅——Divisible Subsequences
Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...
- Kattis之旅——Prime Path
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that ...
- Kattis之旅——Inverse Factorial
题目意思就是已知n的阶乘,求n. 当输入的阶乘小于10位数的时候,我们可以用long long将字符串转化成数字,直接计算. 而当输入的阶乘很大的时候,我们就可以利用位数去大概的估计n. //Asim ...
- Kattis之旅——Perfect Pth Powers
We say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, ...
随机推荐
- GIT中常用的命令
最近项目中使用到了GIT,所以记录一下GIT中常用的命令. GIT使用的客户端有Git Bash:http://code.google.com/p/msysgit/ 还有乌龟TortoiseGit:h ...
- MYSQL PROCEDURE 测试用例
/** * 查询俱协信息 */ DROP PROCEDURE IF EXISTS `get_club_list`; DELIMITER $$ CREATE PROCEDURE `get_club_li ...
- 一、程序设计与C语言
@程序:用特殊的编程语言编写的代码,用于表达如何解决问题. @编程语言的作用:编程语言不是用来和计算机交谈的,而是用它来描述要求计算机如何解决问的过程或方法.计算机只能执行(懂得)机器语言. @辗转相 ...
- MD5、SHA1加密java 16位32位
MD5.SHA1加密java 16位32位 import java.math.BigInteger; import java.security.MessageDigest; public class ...
- Amber中的一些option设置及名词
详细请见AMBER官方文档第18章第6节(18.6) Amber16.pdf The settings can be summarized as follows: imin=1 Choose a m ...
- 关于事件循环机制event loop
setTimeout(()=> { console.log('settimeout') },100) console.log('开始') console.log('结束') new Promis ...
- robot framework自定义python库
自定义python库的好处: robot framework填表式,将python的灵活性弄没了,但是不要担心,RF早就想到了解决办法,就是扩充自己的库. 1.在python应用程序包目录下创建一个新 ...
- System.ArgumentException: 目标数组的长度不够。请检查 destIndex 和长度以及数组的下限
扫码支付接口将要上线,近几天在优化系统性能.昨天把日志Helper类的日志记录改成了使用Queue<T>对象来实现异步处理.做了单元测试,并模拟多线程来测试后,发现正常.今天将站点部署到准 ...
- node.js初识09
1.node_module文件夹 如果你的require中没有写./,那么Node.js将该文件视为node_modules目录下的一个文件. 2.package.json文件 如果使用文件夹来统筹管 ...
- MyBatis基础入门《四》接口方式.Select查询集合
MyBatis基础入门<四>接口方式.Select查询集合 描述: 在<MyBatis基础入门<二>Select查询>中有说过,SQLSession有两种用法,这里 ...