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, ...
随机推荐
- Elemet-技巧
<el-table-column prop="> </el-table-column> 效果: append-to-body 解决el-dialog 弹窗遮罩为题 & ...
- PHP策略模式1
[IUser.php] <?php /** * 策略模式 * 将一组特定的行为和算法封装成类,用来适应某些特定的上下文环境,实现从硬编码到解耦 * 应用举例:电商系统针对不同性别跳转到不同的商品 ...
- 【EatBook】-NO.3.EatBook.3.JavaArchitecture.2.001-《架构探险:从零开始写Java Web框架》-
1.0.0 Summary Tittle:[EatBook]-NO.3.EatBook.3.JavaArchitecture.2.001-<架构探险:从零开始写Java Web框架>- S ...
- [Java in NetBeans] Lesson 07. JavaDoc and Unit Tests
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. organize code into packages Create a package if want to make th ...
- electron 前端开发桌面应用
electron是由Github开发,是一个用Html.css.JavaScript来构建桌面应用程序的开源库,可以打包为Mac.Windows.Linux系统下的应用. 快速开始 接下来,让代码来发 ...
- mysql 延迟添加唯一索引
MySQL [test]> create table tbl_keyword ( -> id int not null auto_increment primary key, -> ...
- Linux配置eclipse实践
有几年没有在Linux下用eclipse开发了,几年前是在CentOS 7下用eclipse开发的,好像用的还是较新的版本.最近有个项目要求在centos 下卡发,装上eclipse-cdt后,建立项 ...
- 递归n!
package sushudigui; import java.util.Scanner; public class digui { public static void main(String[] ...
- vue中使用echarts
1.下载依赖 cnpm i echarts -S 2.模块中引入 <template> <div class="analyzeSystem"> <di ...
- hbase-java-api002(flush)
package api; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apa ...