UVA 10892 - LCM Cardinality(数学题)

题目链接

写写,就ok了。

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <string>

 4 #include <cmath>

 5 #include <ctime>

 6 #include <cstdlib>

 7 #include <iostream>

 8 using namespace std;

 9 #define MOD 1000000

10 #define LL long long

11 int prim[1000001];

12 int o[1000001];

13 int main()

14 {

15     int i,j,num = 0,temp;

16     LL n;

17     for(i = 2;i <= 1000;i ++)

18     {

19         if(!o[i])

20         {

21             for(j = i+i;j <= 1000000;j += i)

22             o[j] = 1;

23         }

24     }

25     for(i = 2;i <= 1000000;i ++)

26     {

27         if(!o[i])

28         prim[num++] = i;

29     }

30     while(cin>>n)

31     {

32         if(!n) break;

33         cout<<n<<" ";

34         LL ans = 1;

35         for(i = 0;i < num;i ++)

36         {

37             temp = 0;

38             while(n%prim[i] == 0)

39             {

40                 temp ++;

41                 n /= prim[i];

42             }

43             ans *= ((temp+1)*2-1);

44         }

45         if(n != 1)

46         ans *= 3;

47         cout<<ans/2 +1<<endl;

48     }

49     return 0;

50 }

你可能感兴趣的:(uva)