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; }
无论前方的路有多么曲折,我都会告诉本身,本身的选择,没有后悔,后退的可能,由于热爱因此坚持,既然已经走上这条路,就走出一点风采!!!函数