Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
可以找出公式,枚举分解数的个数,效率可以达到O(n)#include<iostream> using namespace std; int main() { long n,ans=0,p,i,k,N,j,temp; cin>>N; j=1; while(j<=N) { cin>>temp>>n; p=1; ans=0; for (i=2;p;i++) { k=n/i; if (i%2==0) { if (k-i/2>=0) {if ((2*k+1)*i/2==n) ans++;} else p=0; } else { if (k-(i+1)/2>=0) {if (k*i==n) ans++;} else p=0; } } cout<<temp<<" "<<ans<<endl; j++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator