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 分解质因数的更多相关文章

  1. 【分解质因数】【树状数组】【快速幂】codeforces 2014 ACM-ICPC Vietnam National Second Round E. ACM

    乘除都在150以内,分解质因数后发现只有35个,建立35个树状数组/线段树,做区间加.区间查询,最后快速幂起来. #include<cstdio> #include<cstring& ...

  2. Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论

    题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...

  3. POJ1811(SummerTrainingDay04-G miller-rabin判断素性 && pollard-rho分解质因数)

    Prime Test Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 35528   Accepted: 9479 Case ...

  4. 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树

    [BZOJ4026]dC Loves Number Theory Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源.    给 ...

  5. 【bzoj4459】[Jsoi2013]丢番图 分解质因数

    题目描述 丢番图是亚历山大时期埃及著名的数学家.他是最早研究整数系数不定方程的数学家之一.为了纪念他,这些方程一般被称作丢番图方程.最著名的丢番图方程之一是x^N+y^n=z^N.费马提出,对于N&g ...

  6. BZOJ_4459_[Jsoi2013]丢番图_数学+分解质因数

    BZOJ_4459_[Jsoi2013]丢番图_数学+分解质因数 Description 丢番图是亚历山大时期埃及著名的数学家.他是最早研究整数系数不定方程的数学家之一. 为了纪念他,这些方程一般被称 ...

  7. java分解质因数

      package test; import java.util.Scanner; public class Test19 { /** * 分析:对n进行分解质因数,应先找到一个最小的质数k * 最小 ...

  8. 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)

    1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...

  9. 【python】将一个正整数分解质因数

    def reduceNum(n): '''题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5''' print '{} = '.format(n), : print 'Pleas ...

随机推荐

  1. ajax请求的同步异步问题

    前言 在做项目的过程中遇到一个bug就是:使用了alert语句后,代码才能正确执行,没使用就执行不成功. 后来我就用把console.log,代码就不能正确执行. 于是我就去比较了下consol.lo ...

  2. 切面条|2014年蓝桥杯B组题解析第二题-fishers

    切面条 一根高筋拉面,中间切一刀,可以得到2根面条. 如果先对折1次,中间切一刀,可以得到3根面条. 如果连续对折2次,中间切一刀,可以得到5根面条. 那么,连续对折10次,中间切一刀,会得到多少面条 ...

  3. Inversion of Control Containers and the Dependency Injection pattern

    https://martinfowler.com/articles/injection.html One of the entertaining things about the enterprise ...

  4. 筛选出sql 查询结果中 不包含某个字符

    select * from table1 where patindex('%关键字%' , aa) = 0 select * from table1 where charindex('关键字' , a ...

  5. [Shiro] - shiro之SSM中的使用

    在学习shiro的途中,在github发现了一个开源项目,所需的控件刚好是自己要学习的方向. 虽然还要学习完ssm的shiro与springboot的shiro,以及接下来的种种控件和类库,但学习这个 ...

  6. [Redis] - redis实战

    Microsoft Windows [版本 10.0.17134.472] (c) Microsoft Corporation.保留所有权利. C:\Users\SeeClanUkyo>f: F ...

  7. NS3 MyApp Class Reference

    官方文档:MyApp 可以在下面的几个例子找到: examples/tutorial/fifth.cc examples/tutorial/seventh.cc examples/tutorial/s ...

  8. UVa 253 骰子涂色

    https://vjudge.net/problem/UVA-253 题意:输入两个骰子的六面颜色,判断是否等价. 思路:我最想到的是暴力,不过一直错,也不知道哪里错了.第二种方法就是在一个骰子里出现 ...

  9. python 打包成tar包

    def make_targz(output_filename, source_dir): with tarfile.open(output_filename, "w:gz") as ...

  10. JS + flash 复制

    js代码ZeroClipboard组件制作复制剪切板复制粘贴文字内容,一键即可复制粘贴文字内容.兼容各大主流浏览器firefox,,Chrome,IE等. 演示代码 如下: <script ty ...