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

Problem Description
Given an infinite array of integers 2,3,.... Now do some operations on it.

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
 
打表找规律,将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 = ;
int num[maxn];
int prime[maxn];
int cnt;
char str[]; void init() {
cnt = ;
memset(num, -, sizeof(num));
for (int i = ; i <= (maxn >> ); i ++) {
for (int j = (i << ); j <= maxn; j += i) num[j] = ;
}
for (int i = ; i <= maxn; i ++) {
if (num[i]) prime[cnt ++] = i;
}
} class BigNum {
private:
int a[];
int len;
public:
BigNum() { len = ; memset(a, , 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, , sizeof(a));
L = strlen(s);
len = L / DLEN;
if (L % DLEN) len ++;
index = ;
for (i = L - ; i >= ; i -= DLEN) {
t = ;
k = i - DLEN + ;
if (k < ) k = ;
for (int j = k; j <= i; j ++) t = t * + s[j] - '';
a[index ++] = t;
}
} BigNum::BigNum(const BigNum &T):len(T.len) {
int i;
memset(a, , sizeof(a));
for (i = ; i < len; i ++) a[i] = T.a[i];
} BigNum & BigNum::operator=(const BigNum &n) {
int i;
len = n.len;
memset(a, , sizeof(a));
for (i = ; i < len; i ++) a[i] = n.a[i];
return *this;
} BigNum BigNum::operator/(const int &b) const {
BigNum ret;
int i, down = ;
for (int i = len - ; i >= ; i --) {
ret.a[i] = (a[i] + down * (MAXN + )) / b;
down = a[i] + down * (MAXN + ) - ret.a[i] * b;
}
ret.len = len;
while (ret.a[ret.len - ] == && ret.len > ) ret.len --;
return ret;
} int BigNum::operator%(const int &b) const {
int i, d = ;
for (int i = len - ; i >= ; i --) d = ((d * (MAXN + )) % b + a[i]) % b;
return d;
} void BigNum::print() {
int i;
printf("%d", a[len-]);
for (int i = len - ; i >= ; i --) printf("%04d", a[i]);
printf("\n");
} int main() {
init();
while (~scanf("%s", str)) {
if (str[] == '') break;
if (strlen(str) == && str[] == '') {
printf("no\n");
continue;
}
BigNum n = BigNum(str);
int count;
for (int i = ; i < cnt; i ++) {
count = ;
BigNum tmp = n;
while (tmp % prime[i] == ) {
count ++;
tmp = tmp / prime[i];
if (count >= ) break;
}
if (count >= ) break;
}
if (count >= ) printf("no\n");
else printf("yes\n");
} return ;
}
 
 

HDU2441 ACM(Array Complicated Manipulation)的更多相关文章

  1. CSc 352 (Spring 2019): Assignment

    CSc 352 (Spring 2019): Assignment 11Due Date: 11:59PM Wed, May 1The purpose of this assignment is to ...

  2. leetcode——169 Majority Element(数组中出现次数过半的元素)

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  3. Java Algorithm Problems

    Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...

  4. 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array

    题目描述 Given an array A with length n  a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...

  5. 2017 ACM/ICPC Asia Regional Shenyang Online array array array

    2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...

  6. ACM学习历程—HDU5587 Array(数学 && 二分 && 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后 ...

  7. AndyQsmart ACM学习历程——ZOJ3872 Beauty of Array(递推)

    Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...

  8. [Python Cookbook] Numpy Array Manipulation

    1. Reshape: The np.reshape() method will give a new shape to an array without changing its data. Not ...

  9. “玲珑杯”ACM比赛 Round #4 E -- array DP

    http://www.ifrog.cc/acm/problem/1050?contest=1006&no=4 DP[val]表示以val这个值结尾的等差数列有多少个 DP[val] += DP ...

随机推荐

  1. Python 3基础教程32-正则

    本文介绍Python的正则,通过本文介绍和一个练习,对正则有一个基本了解就可以. # 正则表达式 ''' 正则表达式是有一些特殊字符组成,能够帮你找到一些符合一定规则的字符串 先来了解几个符号所代表的 ...

  2. Python 3基础教程25-异常处理

    在Python中,异常处理,主要是try except语句,通常语法格式如下. try: 代码块1 except Exception as e: print(e) 代码2 接着前面读取CSV文件,如果 ...

  3. ardupilot_gazebo仿真(四)

    ardupilot_gazebo仿真(四) 标签(空格分隔): 未分类 Multi-MAV simulation 参考官网给出的multi-vehicle-simulation的方法 在每次打开sim ...

  4. Python 学习笔记之—— PIL 库

    PIL,全称 Python Imaging Library,是 Python 平台一个功能非常强大而且简单易用的图像处理库.但是,由于 PIL 仅支持到Python 2.7,加上年久失修,于是一群志愿 ...

  5. deeplearning.ai课程学习(1)

    本系列主要是我对吴恩达的deeplearning.ai课程的理解和记录,完整的课程笔记已经有很多了,因此只记录我认为重要的东西和自己的一些理解. 第一门课 神经网络和深度学习(Neural Netwo ...

  6. python中字典的循环遍历的两种方式

    开发中经常会用到对于字典.列表等数据的循环遍历,但是python中对于字典的遍历对于很多初学者来讲非常陌生,今天就来讲一下python中字典的循环遍历的两种方式. 注意: python2和python ...

  7. iOS-登录发送验证码时60秒倒计时,直接用

    __block NSInteger timeout= ; //倒计时时间 KWeakSelf dispatch_queue_t queue = dispatch_get_global_queue(DI ...

  8. C#排序相关算法

    http://www.cnblogs.com/zxjyuan/archive/2010/01/06/1640092.html 冒泡法: Using directivesnamespace Bubble ...

  9. SSH面试集锦——不看后悔哦!

    1.        谈谈你mvc的理解 MVC是Model-View-Controler的简称.即模型-视图-控制器.MVC是一种设计模式,它强制性的把应用程序的输入.处理和输出分开. MVC中的模型 ...

  10. (转)MongoDB numa系列问题三:overcommit_memory和zone_reclaim_mode

    内核参数overcommit_memory : 它是 内存分配策略 可选值:0.1.2.0:表示内核将检查是否有足够的可用内存供应用进程使用:如果有足够的可用内存,内存申请允许:否则,内存申请失败,并 ...