Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <list>
- # include <bitset>
- # include <algorithm>
- # include <sstream>
- # include <iostream>
- # include <cstdlib>
- # include <ctime>
- # include <set>
- # include <map>
- # include <cmath>
- # include <queue>
- # include <limits>
- # include <stack>
- # include <vector>
- # include <cstring>
- # include <cstdio>
- # include <fstream>
- using namespace std;
- int pel(string s){string t;t=s;reverse(t.begin(),t.end());if(s==t)return 1;return 0;}
- string toString(int n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
- int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
- bool isprime(int m){if(m<2) return 0;for( int i=2; i*i<=m ; i++)if(m%i==0)return 0; return 1;return 0;}
- # define __(array,w) memset(array,w,sizeof array)
- # define FOR(i, a, b) for (int i=a; i<b; i++)
- # define REP(i, a) FOR(i,0,a)
- # define all(c) (c).begin(), (c).end()
- # define sz(x) x.size()
- # define MAX INT_MAX
- # define pb push_back
- # define MP make_pair
- # define X first
- # define Y second
- # define SBS(s,a,b) (s).substr(a,b)
- # define UNQ(s) {sort(all(s));(s).erase(unique(all(s)),s.end());}
- # define rive(s) reverse(s.begin(),s.end())
- # define VI vector<int>
- # define VS vector<string>
- # define VC vector<char>
- # define out(a) cout<<#a<<"= "<<a<<endl;
- map<int, int>gonona,asolgonona;
- map<int, int> precal;
- long long divisors(long long n)
- {
- long long divv=1;
- long long i;
- if(n==1){asolgonona[1]=1;return 1;}
- VI vi,vj;
- long long int saved=n;
- for(i=2;i<=(long long )sqrt(n);i++)
- {
- while(n % i == 0)
- {
- n /= i;
- gonona[i]++;
- vi.pb(i);
- }
- if(n!=saved)divv*= ((gonona[i])+1);
- }
- if (n >1) {
- divv*=2;vi.pb(n);}
- long long c=1;
- sort(all(vi));
- REP(i,sz(vi))
- {
- int p=vi[i];
- vj.pb(p);
- FOR(j,i+1,sz(vi))
- {
- p*=vi[j];
- vj.pb(p);
- vj.pb(vi[i]*vi[j]);
- vj.pb(saved/vi[j]);
- }
- }
- UNQ(vi);
- REP(i,sz(vi))
- {
- int p=pow(vi[i],gonona[vi[i]]);
- FOR(j,i+1,sz(vi))
- {
- vj.pb(p*vi[j]);
- }
- }
- gonona.clear();
- sort(all(vj));
- UNQ(vj);
- REP(i,sz(vj))
- {
- c+=vj[i];
- }
- asolgonona[saved]=c;
- return divv;
- }
- void precalcu()
- {
- REP(i,100000)
- {
- precal[i+1]=divisors(i+1);
- //cout<<i+1<<" "<<divisors(i+1)<<" "<<asolgonona[i+1]<<endl;
- }
- }
- int main()
- {
- //freopen("testout.txt","w",stdout);
- precalcu();
- int test;
- cin>>test;
- while(test--)
- {
- int a,b,k;
- cin>>a>>b>>k;
- long long D=0,H=0;
- for(int i=a;i<=b;++i)
- {
- if(i%k==0)
- {
- D+=divisors(i);
- H+=asolgonona[i];
- }
- }
- cout<<D<<" "<<H<<endl;
- asolgonona.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement