暑假练习赛 006 B Bear and Prime 100】的更多相关文章

Bear and Prime 100Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 680C uDebug Description   Input   Output   Sample Input   Sample Output   Hint  …
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the outpu…
A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表:{2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49},询问19次,如果能被整出两次以上,说明是合数,否则是质数. #include<bits/stdc++.h> using namespace std; #define ll long long…
C. Bear and Prime 100 time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number - an i…
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
[题目]A. Bear and Prime 100 [题意]有一数字x,每次可询问一个数字y是否x的因子,最后输出数字x是否素数,要求询问次数<=20. [题解]容易发现[2,100]范围内的非素数一定能分解为[2,47]范围内的素数的乘积,所以只需要询问[2,47]范围内的15个素数. 平方数需要特殊判断,有4,9,16,25,49.(36可以分解为(2*3)^2,不需要特判),恰好20次询问. #include<cstdio> ]={,,,,,,,,,,,,,,,,,,,,}; ];…
题目链接:http://codeforces.com/contest/679/problem/A CF有史以来第一次出现交互式的题目,大致意思为选择2到100中某一个数字作为隐藏数,你可以询问最多20次问题,每一次询问一个数字x,如果预先选定的隐藏数是x的倍数,则回复"yes",否则回复"no",你只需要判那个数字是否为质数(不一定需要知道具体是多少) 如果一个数字是两个质数积的倍数,则这个数字一定是合数,另外需要注意,两个质数是可以相同的.即如果隐藏数是a*b的倍…
链接:传送门 题意:给你一个隐藏数,这个隐藏数在[2,100]之间,现在最多可以询问20次,每次询问的是这个数是不是隐藏数的底数,是为yes,不是为no,每次询问后都需要flush一下输出缓冲区,最后判断这个数是不是素数. 思路:直接打出50以内的素数表,挨个进行询问,用计数器记录出现的因子个数,如果>1则说明为合数,需要特殊处理4,9,16,25,36,49,例如 49 --> 1 7 49 计数器1,但此数仍为合数. /***********************************…
第一次交互题,记录一下吧 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algorithm> #include <cstring> using namespace std; typed…
Vanya and LabelCrawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice _ uDebug Description   Input   Output   Sample Input   Sample Output   Hint   Description While…
Description Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remai…
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和,这个sum数组在打素数表时候就能够求出来,注意一点求素数的内层循环要改成i.不能再写成i + i或者i * i了.原因想想就明确了. 这学期最后一场比赛也结束了,结果不非常惬意但也还好. 总的来说这学收获还是蛮多的. 近期可能就不再做ACM了吧,可能要复习CET6了吧,可能要复习期末考试的内容了吧.…
385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) const int INF=0x3f…
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出现个数时使用了map,以至于后面做前缀和的累加时,每次都要对map进行查询,以至于TLE.而自己一直没有发现,以为是欧拉筛对于这道题还不够优,于是上网搜题解,发现别人的做法几乎一样,但是却能跑过,挣扎了许久才想起是map的原因.map的内部实现是一颗红黑树,每次查询的复杂度为O(logN),在本来时…
/* 可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数, 然后算出[0,s]的个数 [l,r] 的个数即为[0,r]的个数减去[0,l]个数. */ #include <stdio.h> #include <iostream> #include <string.h> #define maxn 10000010 using namespace std; int prime[maxn]; int isprime[maxn]; int x[maxn]; void m…
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represe…
F - Mishka and trip Sample Output   Hint In the first sample test: In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses. In his second test, there's one cycle with 1 vertex and one with 2. No one can…
题意翻译 给你一串数列a.对于一个质数p,定义函数f(p)=a数列中能被p整除的数的个数.给出m组询问l,r,询问[l,r]区间内所有素数p的f(p)之和. 题目描述 Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1,x2,...,xn x_{1},x_{2},...,x_{n} x1​,x2​,.…
题目链接:http://codeforces.com/problemset/problem/385/C 题目大意:给定n个数与m个询问区间,问每个询问区间中的所有素数在这n个数中被能整除的次数之和 解题思路:首先暴力打出一张素数表,最大的素数小于等于n个数中的最大值即可.在打表的过程就统计从2开始到当前素数的总的整除次数(简直简单粗暴),最后对于询问区间,找出该区间内的最小素数与最大素数在素数表中的位置,结果即为s[r]-s[l-1] 代码如下: #include<cmath> #includ…
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample has 3 queries. The first query l = 2, r = 11 comes. You need to count f(2) + f(3) + f(5) + f(7) + f(11) = 2 + 1 + 4 + 2 + 0 = 9. The second query comes…
B - Chris and Road Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice _ uDebug Description   Input   Output   Sample Input   Sample Output   Hint   Description A…
A - Spider Man Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description   Input   Output   Sample Input   Sample Output   Hint   Description Peter Parker wants to p…
E - Pairs Description standard input/outputStatements In the secret book of ACM, it’s said: “Glory for those who write short ICPC problems. May they live long, and never get Wrong Answers” . Everyone likes problems with short statements. Right? Let’s…
C - OCR Description standard input/outputStatements Optical Character Recognition (OCR) is one of the most famous fields of Artificial Intelligence. The main purpose of OCR is to recognize printed text (or handwriting) and convert it to the machine e…
Weird Cryptography Description standard input/outputStatements Khaled was sitting in the garden under an apple tree, suddenly! , well... you should guess what happened, an apple fell on his head! , so he came up with a new Cryptography method!! The m…
题目链接~~> 做题感悟:这题属于想法题,比赛时直接做的 D 题.可是处理坐标处理的头晕眼花的结果到最后也没AC. 解题思路: 由于查询的时候仅仅考虑素数,so~我们仅仅考虑素数就能够,这就须要筛素数.我们能够在筛素数的同一时候把某个素数出现的倍数加上.输入的时候仅仅要记录某个数的个数就能够了. 代码: #include<iostream> #include<sstream> #include<map> #include<cmath> #include…
思路: 需要对埃氏筛法的时间复杂度有正确的认识(O(nlog(log(n)))),我都以为肯定超时了,结果能过. 实现: #include <bits/stdc++.h> using namespace std; ]; vector<int> prime; ], ans[]; void sieve(int n) { ; i <= n; i++) is_prime[i] = true; is_prime[] = is_prime[] = false; ; i <= n;…
传送门 第一道交互题 题意: 电脑事先想好了一个数[,] 你会每次问电脑一个数是否是它想的那个数的因数 电脑会告诉你yes或no 至多询问20次 最后要输出它想的数是质数还是合数 思路: 枚举<50的质数和4,,,49即可判断 ,, ,49单独看作质数是这样方便判断2^,^,...,^ 解释: 在使用多个输出函数连续进行多次输出时,有可能发现输出错误. 因为下一个数据再上一个数据还没输出完毕,还在输出缓冲区中时,下一个printf就把另一个数据加入输出缓冲区, 结果冲掉了原来的数据,出现输出错误…