http://acm.hdu.edu.cn/showproblem.php?pid=1333
2010-08-07 19:38
316 查看
]/* 很简单的题目。直接模拟就好了,可是我开始就是wrong As this observation is also true for every prime number, Wilansky decided later that a (simple and unsophisticated) prime number is not worth being a Smith number, so he excluded them from the definition. 看了这句话,一直没有看懂,原来这句话告诉我们素数是不符合的 晕死了 */ #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; const int N = 40005; bool hash ; int prime[N / 2]; int p; inline void Prime() { memset(hash, false, sizeof(hash)); for(int i = 2; i < sqrt(1.0 * N); i++) if(!hash[i]) for(int j = 2; j * i < N; j++) hash[j * i] = true; p = 0; for(int i = 2; i < N; i++) if(!hash[i]) prime[p++] = i; } inline int Sum(int n) { int sum = 0; while(n) { sum += n % 10; n /= 10; } return sum; } inline bool oula(int n, int kk) { int temp = n; int sum = n; int gf = 0; int r; for(int i = 0; i < p; i++) { if(temp % prime[i] != 0) continue; r = 0; while(temp % prime[i] == 0) { temp /= prime[i]; r++; } gf += Sum(prime[i]) * r; sum = sum / prime[i] * (prime[i] - 1); } if(temp > 1) { sum = sum / temp * (temp - 1); gf += Sum(temp); } if(sum == n - 1) return false; if(gf == kk) return true; return false; } int main() { Prime(); int n; while( scanf("%d", &n) != EOF && n) { n = n + 1; while(true) { if(oula(n, Sum(n))) { printf("%d/n", n); break; } n += 1; } } return 0; }
相关文章推荐
- http://acm.hdu.edu.cn/showproblem.php?pid=1124 N!末尾0的个数
- Quoit Design&&http://acm.hdu.edu.cn/showproblem.php?pid=1007
- http://acm.hdu.edu.cn/showproblem.php?pid=2842
- A + B Problem II &&http://acm.hdu.edu.cn/showproblem.php?pid=1002
- http://acm.hdu.edu.cn/showproblem.php?pid=3015 树状数组
- Encoding http://acm.hdu.edu.cn/showproblem.php?pid=1020
- http://acm.hdu.edu.cn/showproblem.php?pid=1874 简单题
- http://acm.hdu.edu.cn/showproblem.php?pid=1238
- http://acm.hdu.edu.cn/showproblem.php?pid=1863
- http://acm.hdu.edu.cn/showproblem.php?pid=1203(背包问题)
- Max Sum &&http://acm.hdu.edu.cn/showproblem.php?pid=1003
- http://acm.hdu.edu.cn/showproblem.php?pid=1542 矩形面积的并 线段树 + 扫描线 + 离散化
- Oulipo(http://acm.hdu.edu.cn/showproblem.php?pid=1686)
- http://acm.hdu.edu.cn/showproblem.php?pid=1087
- http://acm.hdu.edu.cn/showproblem.php?pid=2441 犀利的证明
- 字符输入时注意的格式(特殊情况)http://acm.hdu.edu.cn/showproblem.php?pid=1860
- http://acm.hdu.edu.cn/showproblem.php?pid=1269
- http://acm.hdu.edu.cn/showproblem.php?pid=1789 很好的贪心题目
- hdu 1085 http://acm.hdu.edu.cn/showproblem.php?pid=1085
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=963&pid=1019&ojid=1