76分,求解!(原主误骂,只是借鉴)
查看原帖
76分,求解!(原主误骂,只是借鉴)
1435980
lijunxian_0818_2楼主2024/11/23 22:38
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll T,k,P,Q,len;
int prime[6000005];
bool isprime[100000005];

inline ll fast_pow(ll unit,ll p){
	ll ans=1;
	while( p ){
		if( p&1 )
			ans=ans*unit%mod;
		unit=unit*unit%mod;
		p>>=1;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	for(ll i=2;i<=1e8;i++){
		if( !isprime[i] )
			prime[++len]=i;
		for(ll j=1;j<=len && i*prime[j]<=1e8;j++){
			isprime[i*prime[j]]=1;
			if( i%prime[j]==0 )
				break;
		}
	}
	cin>>T;
	while( T-- ){
		cin>>k>>P>>Q;
		if( k==1 ){
			cout<<(Q-P+1)%mod<<'\n';
			continue;
		}
		ll ans=0;
		for(int i=1;i<=len;i++){
			if( k%prime[i]==0 ){
				ans++;
				while( k%prime[i]==0 )
					k/=prime[i];
				if( k==1 )
					break;
			}
		}
		if(k>=2) ans++;
		ans=fast_pow(2,ans);
		ans=ans*(Q-P+1)%mod;
		cout<<ans<<'\n';
	}
	return 0;
}
2024/11/23 22:38
加载中...