## 【HDOJ5447】Good Numbers（数论）

int128本机环境跑不了，只能交上去的时候改，总觉得有朝一日要掉坑里

  1 #include<bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 typedef unsigned int uint;
5 typedef unsigned long long ull;
6 typedef long double ld;
7 typedef pair<int,int> PII;
8 typedef pair<ll,ll> Pll;
9 typedef vector<int> VI;
10 typedef vector<PII> VII;
11 typedef pair<ll,ll>P;
12 #define N  1000000+10
13 #define M  200000+10
14 #define INF 1e9
15 #define fi first
16 #define se second
17 #define MP make_pair
18 #define pb push_back
19 #define pi acos(-1)
20 #define mem(a,b) memset(a,b,sizeof(a))
21 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
22 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
23 #define lowbit(x) x&(-x)
24 #define Rand (rand()*(1<<16)+rand())
25 #define id(x) ((x)<=B?(x):m-n/(x)+1)
26 #define ls p<<1
27 #define rs p<<1|1
28 #define fors(i) for(auto i:e[x]) if(i!=p)
29
30 const int MOD=998244353,inv2=(MOD+1)/2;
31       //int p=1e4+7;
32       double eps=1e-6;
33       int dx[4]={-1,1,0,0};
34       int dy[4]={0,0,-1,1};
35
36 int p[N],b[N];
37
39 {
40    int v=0,f=1;
41    char c=getchar();
42    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
43    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
44    return v*f;
45 }
46
48 {
49    ll v=0,f=1;
50    char c=getchar();
51    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
52    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
53    return v*f;
54 }
55
56 template<class T> void Read(T &x)
57 {
58     static int CH;
59     while((CH=getchar())<'0'||CH>'9');
60     for(x=CH-'0';(CH=getchar())>='0'&&CH<='9';x=(x<<3)+(x<<1)+(CH-'0'));
61 }
62
63 int is2(__int128 x)
64 {
65     __int128 t=pow(x,1.0/2)+0.5;
66     if(t*t==x) return 1;
67     return 0;
68 }
69
70 int is3(__int128 x)
71 {
72     __int128 t=pow(x,1.0/3)+0.5;
73     if(t*t*t==x) return 1;
74     return 0;
75 }
76
77 void calc(ll &ans,__int128 x,__int128 y)
78 {
79     if(y==1)
80     {
81         if(x==1) ans*=1;
82          else if(is3(x)) ans*=3;
83           else if(is2(x)) ans*=2;
84            else ans*=1;
85     }
86      else if(y>1&&is2(y))
87      {
88          if(y%x==0) ans*=3;
89           else ans*=2;
90      }
91       else if(x>1&&is2(x))
92       {
93           if(x%y==0) ans*=3;
94            else ans*=2;
95       }
96        else if(y%x==0) ans*=2;
97         else ans*=1;
98 }
99
100 int main()
101 {
102     //freopen("1.in","r",stdin);
103     //freopen("1.out","w",stdout);
104     int n=0;
105     rep(i,2,1e6)
106     {
107         if(!b[i]) p[++n]=i;
108         rep(j,1,n)
109         {
110             int t=p[j]*i;
111             if(t>1e6) break;
112             b[t]=1;
113             if(i%p[j]==0) break;
114         }
115     }
117     while(cas--)
118     {
119         __int128 s1,s2;
122         ll ans1,ans2;
123         ans1=ans2=1;
124         rep(i,1,n)
125         {
126             if(s1%p[i]==0)
127             {
128                 int s=0;
129                 while(s1%p[i]==0)
130                 {
131                     s++;
132                     s1/=p[i];
133                 }
134                 ans1*=s;
135             }
136             if(s2%p[i]==0)
137             {
138                 int s=0;
139                 while(s2%p[i]==0)
140                 {
141                     s++;
142                     s2/=p[i];
143                 }
144                 ans2*=s;
145             }
146         }
147         __int128 k=std::__gcd(s1,s2);
148         calc(ans1,k,s1/k);
149         calc(ans2,k,s2/k);
150         printf("%I64d %I64d\n",ans1,ans2);
151     }
152     return 0;
153 }

posted on 2019-11-22 22:25  myx12345  阅读(253)  评论(0编辑  收藏  举报