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. 【性能调优】一次关于慢查询及FGC频繁的调优经历

    以下来分享一个关于MySQL数据库慢查询和FGC频繁的性能案例. 一.系统架构 一个简单的dubbo服务,服务提供者提供接口,并且提供接口的实现,提供方注册服务到Zookeeper注册中心,然后消费者 ...

  2. Flask Web开发从入门到放弃(一)

    第1章 章节一 01 内容概要 02 内容回顾 03 路飞学城之加入购物车 04 路飞学城之结算 05 路飞学城之立即支付 06 路飞学城之后续计划 07 Flask框架简介和快速使用 08 FLas ...

  3. oracle 数据库字段名与实体类字段名称不匹配的处理方法

    之前公司一直都使用sql server 即使数据库字段名称与实体类名称不相同 可以使用诸如: select id as userId from tb_user 这种写法,可换到了oracle 之后坑爹 ...

  4. Eureka搭建

    Eureka搭建 一.Eureka基本框架搭建 pom.xml文件配置:主要是引入Eureka所依赖的jar包 <?xml version="1.0" encoding=&q ...

  5. BZOJ 2756 SCOI2012 奇怪的游戏 最大流

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2756 Description Blinker最近喜欢上一个奇怪的游戏. 这个游戏在一个 N ...

  6. 【转】V8 之旅: 垃圾回收器

    垃圾回收器是一把十足的双刃剑.其好处是可以大幅简化程序的内存管理代码,因为内存管理无需程序员来操作,由此也减少了(但没有根除)长时间运转的程序的内存泄漏.对于某些程序员来说,它甚至能够提升代码的性能. ...

  7. exec族

    在之前我们已经知道用fork创建子进程后执行的是和父进程相同的程序(但有可能执行不同的代码分支),子进程往往要调用一种exec函数以执行另一个程序.当进程调用一种exec函数时,该进程的用户空间代码和 ...

  8. numEdit

    说明:  利用tedit扩展的数字编辑框,允许设置正负.小数点等(The digital edit box using tedit extended, allowing the set of posi ...

  9. Android webview “location.replace” 不起作用

    js解决方法: function locationReplace(url){ if(history.replaceState){ history.replaceState(null, document ...

  10. Ubuntu下安装LNMP之php7的安装并配置Nginx支持php及卸载php

    据了解,php7是比之前的版本性能快很多的.http://php.net/get/php-7.2.2.tar.gz/from/a/mirror 安装前也可提前将相关依赖库安装好,或者在安装php时若安 ...