由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 怎样求common divisor 最快
相关主题
求救啊!sevis状态被deactivateFacebook总部挂起支持BLM的标志!(图) (转载)
问个puzzleTwitter一个employee就能deactivate trump的Twitter?
工程类转行cs,一定需要学位吗?Can I provide consulting service to my previous employer with an H1B visa? Please help~
G 家面经问一题,新网站要代替旧网站,如何设计一个系统将发给旧网站的请求redirect给新网站?
8 queens问题最好解法是什么?时间复杂度?OPT 加急 收到回复。成功了还是失败了?
问一下Repeated DNA Sequences讨论一道面试题
关于H1b和L1b的问题同时申请h1b和OPT Extension ,打了SEVIS的电话
大家觉得看 facebook 乱不乱?FB的这道题怎么答?
相关话题的讨论汇总
话题: colliders话题: collider话题: success话题: 8201话题: th
进入JobHunting版参与讨论
1 (共1页)
p*****2
发帖数: 21240
1
下边这道题,我优化了半天也不行。有标准求common divisor的快速算法吗?
By 2312 there were n Large Hadron Colliders in the inhabited part of the
universe. Each of them corresponded to a single natural number from 1 to n.
However, scientists did not know what activating several colliders
simultaneously could cause, so the colliders were deactivated.
In 2312 there was a startling discovery: a collider's activity is safe if
and only if all numbers of activated colliders are pairwise relatively prime
to each other (two numbers are relatively prime if their greatest common
divisor equals 1)! If two colliders with relatively nonprime numbers are
activated, it will cause a global collapse.
Upon learning this, physicists rushed to turn the colliders on and off and
carry out all sorts of experiments. To make sure than the scientists'
quickness doesn't end with big trouble, the Large Hadron Colliders' Large
Remote Control was created. You are commissioned to write the software for
the remote (well, you do not expect anybody to operate it manually, do you?).
Initially, all colliders are deactivated. Your program receives multiple
requests of the form "activate/deactivate the i-th collider". The program
should handle requests in the order of receiving them. The program should
print the processed results in the format described below.
To the request of "+ i" (that is, to activate the i-th collider), the
program should print exactly one of the following responses:
"Success" if the activation was successful.
"Already on", if the i-th collider was already activated before the request.
"Conflict with j", if there is a conflict with the j-th collider (that is,
the j-th collider is on, and numbers i and j are not relatively prime). In
this case, the i-th collider shouldn't be activated. If a conflict occurs
with several colliders simultaneously, you should print the number of any of
them.
The request of "- i" (that is, to deactivate the i-th collider), should
receive one of the following responses from the program:
"Success", if the deactivation was successful.
"Already off", if the i-th collider was already deactivated before the
request.
You don't need to print quotes in the output of the responses to the
requests.
Input
The first line contains two space-separated integers n and m (1 ≤&#
8201;n, m ≤ 105) — the number of colliders and the
number of requests, correspondingly.
Next m lines contain numbers of requests, one per line, in the form of
either "+ i" (without the quotes) — activate the i-th collider, or "- i" (
without the quotes) — deactivate the i-th collider (1 ≤ i&#
8201;≤ n).
Output
Print m lines — the results of executing requests in the above given format
. The requests should be processed in the order, in which they are given in
the input. Don't forget that the responses to the requests should be printed
without quotes.
Sample test(s)
input
10 10
+ 6
+ 10
+ 5
- 10
- 5
- 6
+ 10
+ 3
+ 6
+ 3
output
Success
Conflict with 6
Success
Already off
Success
Success
Success
Success
Conflict with 10
Already on
l*****a
发帖数: 14598
2
too long...

.
prime

【在 p*****2 的大作中提到】
: 下边这道题,我优化了半天也不行。有标准求common divisor的快速算法吗?
: By 2312 there were n Large Hadron Colliders in the inhabited part of the
: universe. Each of them corresponded to a single natural number from 1 to n.
: However, scientists did not know what activating several colliders
: simultaneously could cause, so the colliders were deactivated.
: In 2312 there was a startling discovery: a collider's activity is safe if
: and only if all numbers of activated colliders are pairwise relatively prime
: to each other (two numbers are relatively prime if their greatest common
: divisor equals 1)! If two colliders with relatively nonprime numbers are
: activated, it will cause a global collapse.

p*****2
发帖数: 21240
3

简单的话就是求两个数的common divisor.

【在 l*****a 的大作中提到】
: too long...
:
: .
: prime

H***e
发帖数: 476
4
greatest common dividor?
用 euclid吧,很快的

【在 p*****2 的大作中提到】
:
: 简单的话就是求两个数的common divisor.

x******a
发帖数: 6336
5
先求gcd,然后求gcd的所有divisor?

【在 p*****2 的大作中提到】
:
: 简单的话就是求两个数的common divisor.

p*****2
发帖数: 21240
6

这题只要求common divisor 或 1 或 非1就可以了。有什么快的吗?

【在 H***e 的大作中提到】
: greatest common dividor?
: 用 euclid吧,很快的

x******a
发帖数: 6336
7
1肯定是吧
直接return true?

【在 p*****2 的大作中提到】
:
: 这题只要求common divisor 或 1 或 非1就可以了。有什么快的吗?

p*****2
发帖数: 21240
8

不好意思,是只有1,或者有其他的。

【在 x******a 的大作中提到】
: 1肯定是吧
: 直接return true?

x******a
发帖数: 6336
9
Binary GCD algorithm
?

【在 p*****2 的大作中提到】
:
: 不好意思,是只有1,或者有其他的。

1 (共1页)
进入JobHunting版参与讨论
相关主题
FB的这道题怎么答?8 queens问题最好解法是什么?时间复杂度?
问一道 ama的除法题问一下Repeated DNA Sequences
这道题,怎么做呀?关于H1b和L1b的问题
某银行的笔试题大家觉得看 facebook 乱不乱?
求救啊!sevis状态被deactivateFacebook总部挂起支持BLM的标志!(图) (转载)
问个puzzleTwitter一个employee就能deactivate trump的Twitter?
工程类转行cs,一定需要学位吗?Can I provide consulting service to my previous employer with an H1B visa? Please help~
G 家面经问一题,新网站要代替旧网站,如何设计一个系统将发给旧网站的请求redirect给新网站?
相关话题的讨论汇总
话题: colliders话题: collider话题: success话题: 8201话题: th