SRM 596 1000pt
来源:互联网 发布:淘宝不能发布游戏账号 编辑:程序博客网 时间:2024/05/01 12:28
Problem Statement
For an integer n, let F(n) = (n - 0^2) * (n - 1^2) * (n - 2^2) * (n - 3^2) * ... * (n - k^2), where k is the largest integer such that n - k^2 > 0. You are given three long longs lo, hi and divisor. It is guaranteed that divisor will be a prime number. Compute and return the number of integers n between lo and hi, inclusive, such that F(n) is divisible by divisor.
Constraints
-
lo will be between 1 and 1,000,000,000,000, inclusive.
-
hi will be between lo and 1,000,000,000,000, inclusive.
-
divisor will be between 2 and 997, inclusive.
-
divisor will be a prime number.
根据sample可以发现规律,但是一开始我把复杂度考虑错误了,应该是 10^6+10^6 ,我考虑从 10^6 * 10^6 了,这就一直没敢写=、=
实际上只需计算 f(hi)-f(lo-1)
PS:自己的分析能力越来越弱了 =、=
#include<iostream>#include<cstring>using namespace std;class SparseFactorialDiv2{public:int visit[1010];long long cal(long long x,long long divisor){long long ans=0,i;memset(visit,0,sizeof(visit));for(i=0;i*i<=x;i++){if(visit[(i*i) % divisor])continue;visit[(i*i) % divisor]=1;ans+=((x-i*i)/divisor);}return ans;}long long getCount(long long lo, long long hi, long long divisor){return cal(hi,divisor)-cal(lo-1,divisor);}};
- SRM 596 1000pt
- Topcoder SRM 544 1000pt
- tc SRM 554 1000pt
- Topcoder SRM 569 1000pt
- SRM 497 div 2 1000pt
- SRM 499 250pt
- SRM 431 div2 1000pt(好题,数学题)
- 【jzoj3918】【TC Srm 636 Div2 1000pt】【蛋糕】【二分答案】
- SRM 499 DIV2 500pt
- TC SRM 519 600pt
- SRM 613 div1 500pt
- SRM 598 DIV1 500 pt
- TOPCODER/SRM 566 DIVII(250、500、1000题)(1000PT暂未附上代码)
- SRM 144 div I 300pt (模拟)
- topcoder srm 531 div2 600pt
- SRM 814 Div 1 ElectionFraudDiv1(250pt)
- TC SRM 552 DIV1 100PT(数论)
- Topcoder SRM 709 DIV 2 250pt Robofactory solution
- 浮点与memset
- 动态规划之钢条切割
- HDU 2050 折线分割平面
- First blog post
- 待处理的事情1
- SRM 596 1000pt
- win7 系统装SQLServer2000 成功
- Best Time to Buy and Sell Stock III 最佳时间买入卖出股票(最多两次买卖)@LeetCode
- 十进制转二进制、八进制、十六进制的经典程序
- springMVC3
- Observer——观察者模式
- PPPoE(ADSL)中的MTU设置
- 如果你的第一个Flash Media Server 的 HelloWorld程序失败了……
- Aspose.Cells处理EXCEL数据