SGU117 水题 Easy

问题:N个数中有多少个数的M次方能被K整除。

Problem: 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.

解法:注意到每个数不超10000,这个题就沦为水题了。求质数,分解质因数,再依次比较质因数的指数。

Solution: This problem become very easy if you note that each number is not larger than 10000. Calculate the prime numbers, then decompose the numbers into prime factors. Finally, compare the exponents of each prime factors of K and the number.

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int p[10010],q[10010],r[10010];
int n,m,k,pnum,x;
bool f[10010];
int main() {
    pnum = 0;
    memset(f,0,sizeof(f));
    for (int i=2;i<=10005;i++)
        if (!f[i]) {
           p[++pnum] = i;
           for (int j=i;j<=10005;j+=i) f[j] = true;
        }
    while (~scanf("%d%d%d",&n,&m,&k)) {
          memset(q,0,sizeof(q));
          for (int i=1;i<=pnum;i++)
              while (k%p[i]==0) {
                    k /= p[i];
                    q[i]++;
              }
          int sum = 0;
          for (int i=1;i<=n;i++) {
              memset(r,0,sizeof(r));
              scanf("%d",&x);
              for (int j=1;j<=pnum;j++)
                  while (x%p[j]==0) {
                        x /= p[j];
                        r[j]++;
                  }
              bool find = true;
              for (int j=1;j<=pnum;j++) {
                  r[j] *= m;
                  if (r[j]<q[j]) {
                     find = false;
                     break;
                  }
              }
              if (find) sum++;    
          }
          printf("%d\n",sum);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值