题意:给你一个n,m问你1-n里面(x)有多少对gcd(x, n)>=m。
思路:我们可以设n=a*b, x=a*c,此时我们可以知道b,c是互质的,那么就可以用欧拉来求解
/* gyt Live up to every day */ #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<cstring> #include<queue> #include<set> #include<string> #include<map> #include <time.h> #define PI acos(-1) using namespace std; typedef long long ll; typedef double db; const int maxn = 1e6+10; const ll maxm = 1e7; const ll mod = 1e9 + 7; const int INF = 0x3f3f3f; const ll inf = 1e15 + 5; const db eps = 1e-9; const int kind=26; ll euler(ll n){ ll res=n,a=n; for(ll i=2;i*i<=a;i++){ if(a%i==0){ res=res/i*(i-1); while(a%i==0) a/=i; } } if(a>1) res=res/a*(a-1); return res; } void solve() { ll n, m; scanf("%lld%lld", &n, &m); ll ans=0; for (ll i=1; i*i<=n; i++) { if (n%i==0) { if (i>=m) ans+=euler(n/i); if (n/i>=m&&i*i!=n) ans+=euler(i); } } cout<<ans<<endl; } int main() { int t = 1; // freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); scanf("%d", &t); while(t--) solve(); return 0; }
时间: 2024-11-12 14:48:05