快速切题 sgu117. Counting 分解质因数
117. Counting
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
Find amount of numbers for given sequence of integer numbers such that after raising them to the M-th power they will be divided by K.
Input
Input consists of two lines. There are three integer numbers N, M, K (0<N, M, K<10001) on the first line. There are N positive integer numbers − given sequence (each number is not more than 10001) − on the second line.
Output
Write answer for given task.
Sample Input
4 2 50
9 10 11 12
Sample Output
1
用时:30min
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxnum=10001;
bool isntprime[maxnum];
int prime[maxnum],cnt;
int divide[maxnum][15],num[maxnum],len[maxnum][15];//divide[i][j]为分解i得到的第j个质数 len[i][j]为分解i得到的第j个质数在i中出现的次数 num[i]为分解i得到的质因数个数
int n,m,k;
void calc(){
cnt=0;
for(int i=2;i<maxnum;i++){
if(!isntprime[i]){
prime[cnt++]=i;
divide[i][0]=i;
num[i]=1;
len[i][0]=1;
for(int j=i+i;j<maxnum;j+=i){
isntprime[j]=true;
divide[j][num[j]]=i;
int tmp=j;
while(tmp%i==0){
tmp/=i;
len[j][num[j]]++;
}
num[j]++;
}
}
}
} int main(){
calc();
scanf("%d%d%d",&n,&m,&k);
if(k==1){printf("%d",n);return 0;}
int ans=0;
for(int i=0;i<n;i++){
int tmp;
scanf("%d",&tmp);
bool fl=true;
for(int j=0;j<num[k];j++){
int fnd=(lower_bound(divide[tmp],divide[tmp]+num[tmp],divide[k][j]))-divide[tmp];
if(fnd>=num[tmp]){fl=false;break;}
if(divide[tmp][fnd]!=divide[k][j]){fl=false;break;}
if(len[tmp][fnd]*m<len[k][j]){fl=false;break;}
}
if(fl)ans++;
}
printf("%d\n",ans);
return 0;
}
快速切题 sgu117. Counting 分解质因数的更多相关文章
- 【分解质因数】【树状数组】【快速幂】codeforces 2014 ACM-ICPC Vietnam National Second Round E. ACM
乘除都在150以内,分解质因数后发现只有35个,建立35个树状数组/线段树,做区间加.区间查询,最后快速幂起来. #include<cstdio> #include<cstring& ...
- Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论
题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...
- POJ1811(SummerTrainingDay04-G miller-rabin判断素性 && pollard-rho分解质因数)
Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 35528 Accepted: 9479 Case ...
- 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树
[BZOJ4026]dC Loves Number Theory Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给 ...
- 【bzoj4459】[Jsoi2013]丢番图 分解质因数
题目描述 丢番图是亚历山大时期埃及著名的数学家.他是最早研究整数系数不定方程的数学家之一.为了纪念他,这些方程一般被称作丢番图方程.最著名的丢番图方程之一是x^N+y^n=z^N.费马提出,对于N&g ...
- BZOJ_4459_[Jsoi2013]丢番图_数学+分解质因数
BZOJ_4459_[Jsoi2013]丢番图_数学+分解质因数 Description 丢番图是亚历山大时期埃及著名的数学家.他是最早研究整数系数不定方程的数学家之一. 为了纪念他,这些方程一般被称 ...
- java分解质因数
package test; import java.util.Scanner; public class Test19 { /** * 分析:对n进行分解质因数,应先找到一个最小的质数k * 最小 ...
- 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)
1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...
- 【python】将一个正整数分解质因数
def reduceNum(n): '''题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5''' print '{} = '.format(n), : print 'Pleas ...
随机推荐
- noip 2012 提高组 day2 部分题解
这道题有多种解法,我用的是扩展欧几里得算法求到的答案 #include<iostream> #include<fstream> #include<cstdio> u ...
- JAVA I/O(六)多路复用IO
在前边介绍Socket和ServerSocket连接交互的过程中,读写都是阻塞的.套接字写数据时,数据先写入操作系统的缓存中,形成TCP或UDP的负载,作为套接字传输到目标端,当缓存大小不足时,线程会 ...
- Max Factor(素数筛法)题解
Max Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- mysql 通过binlog 查看执行日志
环境:linux deepin15.7 mysql 5.7 1.开启binlog vim /etc/mysql/mysql.conf.d/mysqld.cnf 添加 log_bin = /var/ ...
- LA 3644 易爆物
https://vjudge.net/problem/UVALive-3644 简单的并查集题目. #include<iostream> using namespace std; + ; ...
- Java中的垃圾回收机制
1. 垃圾回收的意义 在C++中,对象所占的内存在程序结束运行之前一直被占用,在明确释放之前不能分配给其它对象:而在Java中,当没有对象引用指向原先分配给某个对象的内存时,该内存便成为垃圾.JVM的 ...
- 指数循环节 求A的B次方模C
phi(c)为欧拉函数, 欧拉定理 : 对于互质的正整数 a 和 n ,有 aφ(n) ≡ 1 mod n . A^x = A^(x % Phi(C) + Phi(C)) (mod C) (x & ...
- get-post区别
原文链接:http://www.techweb.com.cn/network/system/2016-10-11/2407736.shtml GET和POST是HTTP请求的两种基本方法,要说它们的区 ...
- mysql 将一张表里的数据插入到另一张表
1. 表结构一样 insert into 表1 select * from 表2 2. 表结构不一样 insert into 表1 (列名1,列名2,列名3) select 列1,列2,列3 from ...
- dns未设置 PHP Warning: file_get_contents():php_network_getaddresses: getaddrinfo failed:
php通过去访问外部网站时,出现以下提示: PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed ...