SDUT 1505 GCD(欧拉函数)

题目链接

基本上跟上个题一模一样。居然因为INT64 CE了两次,哭死。。。

 1 #include <iostream>

 2 #include <cstdio>

 3 #include <cstring>

 4 #include <cstdlib>

 5 #include <vector>

 6 #include <cmath>

 7 #include <map>

 8 #define ll long long

 9 using namespace std;

10 ll euler(ll n)

11 {

12     ll i,m = (ll)sqrt(n + 0.5),ans = n;

13     for(i = 2;i <= m;i ++)

14     {

15         if(n%i == 0)

16         ans = ans/i*(i-1);

17         while(n%i == 0) n /= i;

18     }

19     if(n > 1) ans = ans/n*(n-1);

20     return ans;

21 }

22 int main()

23 {

24     int i,t;

25     ll n,ans,m;

26     scanf("%d",&t);

27     while(t--)

28     {

29         scanf("%lld%lld",&n,&m);

30         ans = 0;

31         for(i = 1;i*i <= n;i ++)

32         {

33             if(n%i == 0)

34             {

35                 if(i >= m)

36                 ans += euler(n/i);

37                 if(i*i != n&&n/i >= m)

38                 ans += euler(i);

39             }

40         }

41         printf("%lld\n",ans);

42     }

43     return 0;

44 }

你可能感兴趣的:(GC)