Solved.
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int mp[10]; 5 6 int main() 7 { 8 mp[7] = mp[5] = mp[3] = 1; 9 int x; cin >> x; 10 puts(mp[x] ? "YES" : "NO"); 11 }
Solved.
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 char s[20]; 5 6 int f(int x) 7 { 8 int res = 0; 9 for (int i = 0; i < 3; ++i) res = res * 10 + s[i + x] - ‘0‘; 10 return res; 11 } 12 13 int main() 14 { 15 while (scanf("%s", s + 1) != EOF) 16 { 17 int res = 0x3f3f3f3f, len = strlen(s + 1); 18 for (int i = 1; i <= len - 2; ++i) res = min(res, abs(f(i) - 753)); 19 printf("%d\n", res); 20 } 21 return 0; 22 }
Solved.
题意:
找出$[1, n]中有多少个只由‘7‘, ‘5‘, ‘3‘ 组成,并且每个字符至少出现一次的数$
思路:
这样的数不会太多,DFS构造,然后二分
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 vector <int> v; 5 6 bool ok(int x) 7 { 8 int flag[10] = {false}; 9 while (x) 10 { 11 flag[x % 10] = 1; 12 x /= 10; 13 } 14 if (flag[3] == 0 || flag[5] == 0 || flag[7] == 0) return false; 15 return true; 16 } 17 18 void DFS(int cur, int num) 19 { 20 if (cur == 10) 21 { 22 if (ok(num)) v.push_back(num); 23 return; 24 } 25 DFS(cur + 1, num); 26 DFS(cur + 1, num * 10 + 3); 27 DFS(cur + 1, num * 10 + 5); 28 DFS(cur + 1, num * 10 + 7); 29 } 30 31 int main() 32 { 33 DFS(0, 0); 34 sort(v.begin(), v.end()); 35 v.erase(unique(v.begin(), v.end()), v.end()); 36 int n; 37 while (scanf("%d", &n) != EOF) printf("%d\n", (int)(upper_bound(v.begin(), v.end(), n) - v.begin())); 38 return 0; 39 }
Upsolved.
题意:
有$N!中所有因子中,有多少因子其拥有的因子个数恰好为75个$
思路:
我们考虑$75 = 75 \cdot 1 = 25 \cdot 3 = 15 \cdot 5 = 5 \cdot 5 \cdot 3$
那么我们处理出$N!中每个质因子一共有多少个,然后考虑质因子个数如何组成因子个数$
考虑一个数$x = a_1^{p_1} \cdot a_2^{p_2} \cdot a_3^{p_3}$
那么$a_1 可以提供的因子个数为 (p_1 + 1) 那么x 的因子个数即 (p_1 \cdot p_2 \cdot p_3)$
然后简单组合一下就可以了
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n; 5 int cnt[110]; 6 int tot[2100]; 7 8 int f(int l, int r) 9 { 10 int res = 0; 11 for (int i = l; i <= r; ++i) res += tot[i]; 12 return res; 13 } 14 15 int main() 16 { 17 while (scanf("%d", &n) != EOF) 18 { 19 memset(cnt, 0, sizeof cnt); 20 memset(tot, 0, sizeof tot); 21 for (int i = 2; i <= n; ++i) 22 { 23 int tmp = i; 24 for(int j = 2; ; ++j) 25 { 26 while (tmp % j == 0) 27 { 28 ++cnt[j]; 29 tmp /= j; 30 } 31 if (tmp == 1) break; 32 } 33 } 34 for (int i = 2; i <= 100; ++i) ++tot[cnt[i] + 1]; 35 int res = f(75, 2000); 36 res += f(25, 2000) * f(3, 24); 37 res += f(25, 2000) * (f(25, 2000) - 1); 38 res += f(15, 2000) * f(5, 14); 39 res += f(15, 2000) * (f(15, 2000) - 1); 40 res += (f(5, 2000) * (f(5, 2000) - 1) / 2) * f(3, 4); 41 res += ((f(5, 2000) * (f(5, 2000) - 1) / 2) * (f(5, 2000) - 2)); 42 printf("%d\n", res); 43 } 44 return 0; 45 }
原文地址:https://www.cnblogs.com/Dup4/p/10055835.html
时间: 2024-11-03 11:49:08