InputThe first line of input is an integer T(T<=100) representing the number of test cases. The following T lines each contains two numbers N and M (2<=N<=1000000000, 1<=M<=N), representing a test case.OutputFor each test case,output the answer on a single line.Sample Inputios
3 1 1 10 2 10000 72
Sample Outputide
1 6 260
題意:給你一個t表示測試組數,每一組數據給你兩個數n,m(範圍2~1e8),求在小於等於n的數中,有多少數知足gcd(i,n)>=m;
思路:很明顯是一個歐拉函數,可是它的gcd不是一是m,所以咱們要把它化爲m,gcd爲一,乘上m,gcd不就是m了嗎
所以,咱們要找n全部因子,
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <map> #define Mod 1000000007 using namespace std; typedef long long ll; const ll N = 3000000+10; map<ll,ll> elh; long long a,b; ll sum [N]; ll Euler(ll n) { if(n==1)return 1; ll res =n; for(ll i=2;i<=n/i;i++) { if(n%i==0) { res = res -res/i; } while(n%i==0)n/=i; } if(n>1)res -= res/n; return res; } int main() { int t; cin >>t; while(t--) { scanf("%lld%lld",&a,&b); ll sum =0; for(int i=1;i<=a/i;i++) { if(a%i==0) { if(i>=b) { sum +=Euler(a/i); } if(a/i>=b&&a/i!=i) { sum+=Euler(i); } } } cout <<sum<<endl; } return 0; }
無論前方的路有多麼曲折,我都會告訴本身,本身的選擇,沒有後悔,後退的可能,由於熱愛因此堅持,既然已經走上這條路,就走出一點風采!!!函數