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, ...
随机推荐
- sap 提供服务
1: https://blog.csdn.net/stone0823/article/details/81661261?utm_source=blogxgwz1 https://blog.csdn.n ...
- fasttext学习笔记
When to use FastText? The main principle behind fastText is that the morphological structure of a wo ...
- centos上shellcheck的安装
关于shellcheck的作用和功能,自行查阅. centos7 上安装shellcheck的过程中查了很多资料,大部分都是在ubunt下安装的,centos的比较少,然后好不容易看到一个https: ...
- 【产品案例】我是如何从零搭建起一款健身O2O产品的?
作者: Wander_Yang 我在年初参与到“SHAPE”这款健身产品的研发中,也算是第一次以产品经理的身份,从0开始负责一个产品的建立. 产品是一款O2O的智能健身连锁店,目前产品已经上线8个月, ...
- [转]sqlserver2014两台不同服务器上数据库同步
https://www.cnblogs.com/peng0731/p/7359465.html 同步了快一个月了,因为途中比较麻烦,第一次,遇到烦的地方就停下了,今天终于同步成功了,哈哈,下面我就来介 ...
- 解决PuTTY中文乱码
转载:http://lhdeyx.blog.163.com/blog/static/3181969720091115113716947/ 打开putty,选择 Category中的Windows--- ...
- gdb强制生成core文件
如何为自己的进程产生core 文件,又不想退出这个进程? 系统只在程序崩溃退出时自动产生core file. 有的人像自己处理异常信号,然后自己产生一个core file,然后继续运行.那该怎么办呢? ...
- vue中动态绑定class
我用的element-ui primary默认是这个颜色,ui设计的是这个颜色所以我们先要重写 .el-button--primary的样式 因为默认是没有勾选的所有事灰色所以下面重写样式为灰色 .e ...
- FlexViewer之整体框架解析
参考:https://www.cnblogs.com/naaoveGIS/p/3915912.html GIS之家:https://xiaozhuanlan.com/gishome 小专栏:https ...
- 使用Spark下的corr计算皮尔森相似度Pearson时,报错Can only zip RDDs with same number of elements in each partition....
package com.huawei.bigdata.spark.examples import org.apache.spark.mllib.stat.Statistics import org.a ...