Advertisement
code_hacker

Untitled

Sep 9th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int t;
  9.     cin>>t;
  10.     for(int w=0;w<t;w++){
  11.         unsigned long long n,k,a,b,count1=0,count2=0;
  12.         cin>>n>>k;
  13.         unsigned long long ub=(n*n)+(2*n);
  14.         ub=min(ub,k-1);
  15.        
  16.         for(a=n+1;a<=ub;a++){
  17.             unsigned long long r=a/(a-n);
  18.             r=r+1ULL;
  19.             unsigned long long u_bound=(n*((r*(a-n))-1ULL))/(((r-1ULL)*a)-(r*n));
  20.        
  21.             u_bound=min(u_bound,k-1);
  22.             for(b=a;b<=u_bound;b++){
  23.                 unsigned long long div=((a*b)-n);
  24.                 unsigned long long divisor=(a-n)*(b-n);
  25.                 unsigned long long rem=div%divisor;
  26.                 if((rem==0ULL)&&(a==b)){
  27.                     count1++;
  28.                 }
  29.                
  30.                 if((rem==0ULL)&&(a!=b)){
  31.                     count2++;
  32.                 }
  33.                
  34.             }
  35.         }
  36.        
  37.         unsigned long long count=(2ULL * count2) + count1;
  38.         cout<<count<<"\n";
  39.     }
  40.    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement