1.712!配对

xiaoxiao2021-03-01  89

                                       1.7    12!配对

1.7.1 题目内容

    找出输入数据中所有两两相乘的积为 12!的个数。输入描述:输入数据中含有一些整数 n(1≤n< )。输出描述:输出所有两两相乘的积为 12!的个数。输入样例  1 10000 159667200 9696 38373635  1000000 479001600 3 1 479001600 输出样例  3 

#include <iostream> #include <set> using namespace std; int main(int argc, char* argv[]) { int num=0; int f12=479001600; //多重集合,允许值重复 multiset<unsigned int>s; int n; while(cin>>n) { if(f12%n==0)//n 是 f12 的约数吗? { //多重集合中有 n 的因子吗 multiset<unsigned int>::iterator it=s.find(f12/n); if(it!=s.end()) { num++; s.erase(it);//从多重集合中删除该因子 } else s.insert(n);//插入到多重集合中 } } cout<<num<<endl;//输出因子对数 return 0; }

 

转载请注明原文地址: https://www.6miu.com/read-4200250.html

最新回复(0)