problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing4319 命名空间参考

  1. 合适数对
更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (acwing4319, case1)
 

详细描述

  1. 合适数对

函数说明

◆ main()

int acwing::acwing4319::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing.cpp5898 行定义.

5898 {
5899 unsigned int n;
5900 unsigned int k;
5901 cin >> n >> k;
5902 vector<unsigned int> a(n);
5903 vector<vector<pair<unsigned int, unsigned int>>> factors(n);
5904 map<vector<pair<unsigned int, unsigned int>>, unsigned int> factor_status_count;
5905 for(int i = 0; i < n; i++) {
5906 cin >> a[i];
5907 for(unsigned int factor = 2; factor * factor <= a[i]; factor++) {
5908 if(a[i] % factor != 0U) {
5909 continue;
5910 }
5911 unsigned int count = 0;
5912 while(a[i] % factor == 0) {
5913 a[i] /= factor;
5914 ++count;
5915 }
5916 count %= k;
5917 if(count != 0) {
5918 factors[i].emplace_back(factor, count);
5919 }
5920 }
5921 if(a[i] != 1) {
5922 factors[i].emplace_back(a[i], 1);
5923 }
5924 }
5925 unsigned long long ans = 0;
5926 for(unsigned int i = 0; i < n; i++) {
5927 vector<pair<unsigned int, unsigned int>> factor_status;
5928 for(auto [factor, count]: factors[i]) {
5929 factor_status.emplace_back(factor, k - count);
5930 }
5931 ans += factor_status_count[factor_status];
5932 ++factor_status_count[factors[i]];
5933 }
5934 cout << ans;
5935 return 0;
5936 }

被这些函数引用 TEST().

◆ TEST()

acwing::acwing4319::TEST ( acwing4319  ,
case1   
)

在文件 acwing_test.cpp2790 行定义.

2790 {
2791 istringstream in("6 3\n1 3 9 8 24 1");
2792 auto out = ostringstream();
2793 main(in, out);
2794 const auto ans = out.str();
2795 ASSERT_EQ("5", ans);
2796 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().