B - Indivisibility
IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the prediction on the number of people who will buy the game.
Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10.
12
2
WA1代码:http://paste.ubuntu.com/23809810/
WA2代码:http://paste.ubuntu.com/23809814/
AC代码:http://paste.ubuntu.com/23809806/
题解:这题的大意就是输入一个数N,然后输出1——N之间不能被2~10整除的数字的个数
WA第一次的原因:使用了过于复杂的判断和计算,导致了超出时间限制
WA第二次的原因:纯属自己作死,忘记把sum定义为long long。
解题思路:首先不能被2~10 整除
那么其实我们实际要考虑的情况只有2,3,5,7这四种。【当一个数能被4整除时必然能被2整除】
然后如AC代码中所写,但是后面为什么要加上呢?当N-N/2-N/3-N/5-N/7时,其实有些数字是被减去了多次,如6,10,14等,当后面选择加上时,又会有些数字重新被加上,相当于没有处理。最后得出的这个算式则是使这些特殊的数字,刚好都被减去了一次。