HDU2441 ACM(Array Complicated Manipulation)
2015-10-22 20:09
176 查看
ACM(Array Complicated Manipulation)
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 513 Accepted Submission(s): 104
The operation is to choose a minimum number from the array which is never been chosen, then change the status of its multiples excluding itself, i.e remove the multiples of the chosen number if they are in the array , otherwise add it to the array.keep the order after change.
For instance, the first step, choose number 2, change the status of 4, 6, 8, 10... They are all removed from the array. The second step, choose 3, change the status of 6, 9, 12, 15...
Pay attention: 9 and 15 are removed from the array while 6 and 12 are added to the array. Input Every line contains an integer n. The zero value for n indicates the end of input.
Output Print "yes" or "no" according whether n is in the array.
Sample Input 2 30 90 0 Sample Output yes yes no Hint The number n never has a prime factor greater than 13000000, but n may be extremely large. Source 2008 Asia Harbin Regional Contest Online 打表找规律,将x质因数分解,假设x=prime1^k1 + prime2^k2 + ...,如果存在某个ki>=2,则输出no,否则输出yes。。。这么复杂的规律不知道网上的大神们是怎么发现的,至于严格证明我也不想看了=_=,主要是复习下筛选法打素数表,另外kuangbin神的大数模板真好用~
/* ID: LinKArftc PROG: 2441.cpp LANG: C++ */ #include <map> #include <set> #include <cmath> #include <stack> #include <queue> #include <vector> #include <cstdio> #include <string> #include <utility> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define eps 1e-8 #define randin srand((unsigned int)time(NULL)) #define input freopen("input.txt","r",stdin) #define debug(s) cout << "s = " << s << endl; #define outstars cout << "*************" << endl; const double PI = acos(-1.0); const double e = exp(1.0); const int inf = 0x3f3f3f3f; const int INF = 0x7fffffff; typedef long long ll; #define DLEN 4 #define MAXN 9999 const int maxn = 66000; int num[maxn]; int prime[maxn]; int cnt; char str[1000]; void init() { cnt = 0; memset(num, -1, sizeof(num)); for (int i = 2; i <= (maxn >> 1); i ++) { for (int j = (i << 2); j <= maxn; j += i) num[j] = 0; } for (int i = 2; i <= maxn; i ++) { if (num[i]) prime[cnt ++] = i; } } class BigNum { private: int a[1000]; int len; public: BigNum() { len = 1; memset(a, 0, sizeof(a)); } BigNum(const char*); BigNum(const BigNum &); BigNum &operator=(const BigNum &); BigNum operator+(const BigNum &) const; BigNum operator-(const BigNum &) const; BigNum operator*(const BigNum &) const; BigNum operator/(const int &) const; int operator%(const int &) const; void print(); }; BigNum::BigNum(const char*s) { int t, k, index, L, i; memset(a, 0, sizeof(a)); L = strlen(s); len = L / DLEN; if (L % DLEN) len ++; index = 0; for (i = L - 1; i >= 0; i -= DLEN) { t = 0; k = i - DLEN + 1; if (k < 0) k = 0; for (int j = k; j <= i; j ++) t = t * 10 + s[j] - '0'; a[index ++] = t; } } BigNum::BigNum(const BigNum &T):len(T.len) { int i; memset(a, 0, sizeof(a)); for (i = 0; i < len; i ++) a[i] = T.a[i]; } BigNum & BigNum::operator=(const BigNum &n) { int i; len = n.len; memset(a, 0, sizeof(a)); for (i = 0; i < len; i ++) a[i] = n.a[i]; return *this; } BigNum BigNum::operator/(const int &b) const { BigNum ret; int i, down = 0; for (int i = len - 1; i >= 0; i --) { ret.a[i] = (a[i] + down * (MAXN + 1)) / b; down = a[i] + down * (MAXN + 1) - ret.a[i] * b; } ret.len = len; while (ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len --; return ret; } int BigNum::operator%(const int &b) const { int i, d = 0; for (int i = len - 1; i >= 0; i --) d = ((d * (MAXN + 1)) % b + a[i]) % b; return d; } void BigNum::print() { int i; printf("%d", a[len-1]); for (int i = len - 2; i >= 0; i --) printf("%04d", a[i]); printf("\n"); } int main() { init(); while (~scanf("%s", str)) { if (str[0] == '0') break; if (strlen(str) == 1 && str[0] == '1') { printf("no\n"); continue; } BigNum n = BigNum(str); int count; for (int i = 0; i < cnt; i ++) { count = 0; BigNum tmp = n; while (tmp % prime[i] == 0) { count ++; tmp = tmp / prime[i]; if (count >= 2) break; } if (count >= 2) break; } if (count >= 2) printf("no\n"); else printf("yes\n"); } return 0; }
相关文章推荐
- 使用GetType()进行类型比较和使用typeof()获取类型
- iOS 分类(Categories)与类的拓展 ( Extensions)
- #在蓝懿学习iOS的日子#Day2
- 使用hibernate 5.02
- VS2010 Windows API 串口编程 (二)
- jdk新特性之泛型
- poj 2499 binary tree (平衡二叉树)
- UVA_11817_TunnellingTheEarth
- Parallax:视差视图
- [No000028]Python的使用之禅及程序员应该明白的一些道理
- 词法分析实验总结
- js 邮政编码验证
- 红黑树实现
- JS学习日记-one
- verilog笔试题
- Android init进程概述
- block循环引用的理解和self.navigationController的理解
- Mysql的Bin log数据恢复:不小心删除数据库
- 数据库的几个概念:主键,外键,索引,唯一索引
- 可重入与线程安全(Reentrancy and Thread-Safety)