Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

可以找出公式,枚举分解数的个数,效率可以达到O(n)

Posted by xijunlee93 at 2013-04-18 20:55:31 on Problem 2853
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator