前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ACMSGURU 117 - Counting

ACMSGURU 117 - Counting

作者头像
Reck Zhang
发布2021-08-11 10:50:41
2610
发布2021-08-11 10:50:41
举报
文章被收录于专栏:Reck Zhang

Counting

Problem Description

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

代码语言:javascript
复制
4 2 50
9 10 11 12

Sample Output

代码语言:javascript
复制
1

Solution

代码语言:javascript
复制
#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);

    auto factors = [](int x) -> std::map<int, int> {
        std::map<int, int> res{};
        for(int i = 2; i * i <= x; i++) {
            if(x % i == 0) {
                int cnt = 0;
                while(x % i == 0) {
                    x /= i;
                    cnt += 1;
                }
                res[i] = cnt;
            }
        }
        if(x != 1) {
            res[x] = 1;
        }
        return res;
    };

    int n, m, k;
    std::cin >> n >> m >> k;
    auto k_factors = factors(k);

    int count = 0;
    while(n--) {
        int num;
        std::cin >> num;
        auto num_factors = factors(num);
        bool is_divided = true;
        for(const auto& k_factor : k_factors) {
            auto it = num_factors.find(k_factor.first);
            if(it == num_factors.end() || it->second * m < k_factor.second) {
                is_divided = false;
                break;
            }
        }
        count += is_divided;
    }

    std::cout << count << std::endl;
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-12-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Counting
    • Problem Description
      • Input
        • Output
          • Sample Input
            • Sample Output
              • Solution
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档