首页 > 代码库 > CodeM资格赛5

CodeM资格赛5

早上起床太晚,最后没时间了。。

不是ac代码,下次题目在oj上线的时候再去做一下。。

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<vector>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<set>
 8 using namespace std;
 9 
10 int map[10];
11 int getHigh(int a) {
12     while (a >= 10) {
13         a /= 10;
14     }
15     return a;
16 }
17 void count(vector<int>& p, vector<int>& u, int size, int pos) {    
18     if (u.size() == size) {
19         int sum = 1;
20         for (int j = 0;j < size;j++)
21             sum *= u[j];
22         map[getHigh(sum)]++;
23         return;
24     }
25     if (pos >= p.size()) return;
26     //if (size - u.size() > p.size() - pos) return;    
27     for (int i = pos;i < p.size();i++) {
28         u.push_back(p[i]);
29         if (size - u.size() > p.size() - i-1) {
30             u.pop_back();
31             /*while (i + 1 < p.size() && p[i + 1] == p[i]) i++;
32             continue;*/
33             return;
34         }
35         count(p, u, size, i + 1);
36         u.pop_back();
37         while (i+1<p.size()&&p[i + 1] == p[i]) i++;
38     }
39 }
40 void getAllPrime(int k)
41 {
42     vector<int> prime;
43     int temp = k;
44     //prime.push_back(1);
45 
46     if (k < 2) return;
47     else if (k == 2)
48         prime.push_back(2);
49     else
50     {
51         for (int i = 2;i<=sqrt(k);i++)
52         {
53             while (k != i) //这里用while循环是考虑到质因子中有可能有重复个i的情况
54             {
55                 if (k%i == 0)
56                 {
57                     prime.push_back(i);
58                     k = k / i;
59                 }
60                 else
61                     break;
62             }
63         }
64         prime.push_back(k);
65     }
66     
67     //for (int i = 0;i<prime.size();i++)
68     //    cout << prime[i] << endl;
69 
70     for (int i = 1;i <= prime.size();i++) {
71         vector<int> u;
72         count(prime, u, i, 0);
73     }
74 }
75 
76 
77 int main()
78 {
79     int l, r;
80     cin >> l >> r;    
81     memset(map, 0, sizeof(map));
82     
83     //1直接算
84     map[1] = r - l + 1;
85     for (int i = l;i <= r;i++) {
86         getAllPrime(i);
87     }
88     for (int j = 1;j <= 9;j++)
89         cout << map[j] << endl;
90     //PrimeDecomposition(l);
91     return 0;
92 }

 

CodeM资格赛5