C - Aladdin and the Flying Carpet
Posted jaydenouyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C - Aladdin and the Flying Carpet相关的知识,希望对你有一定的参考价值。
1 #include<bitset> 2 #include<map> 3 #include<vector> 4 #include<cstdio> 5 #include<iostream> 6 #include<cstring> 7 #include<string> 8 #include<algorithm> 9 #include<cmath> 10 #include<stack> 11 #include<queue> 12 #include<set> 13 #define inf 0x3f3f3f3f 14 #define mem(a,x) memset(a,x,sizeof(a)) 15 16 using namespace std; 17 typedef long long ll; 18 19 //输入挂 20 inline ll in() 21 { 22 ll res=0;char c; 23 while((c=getchar())<‘0‘ || c>‘9‘); 24 while(c>=‘0‘ && c<=‘9‘)res=res*10+c-‘0‘,c=getchar(); 25 return res; 26 } 27 28 const int N=1000010; 29 ll prime[79000]; 30 int p; 31 bitset<N> vis; 32 33 void init() 34 { 35 for(int i=2;i<N;i++) 36 { 37 if(!vis[i]) 38 { 39 prime[p++]=i; 40 for(int j=i+i;j<N;j+=i) 41 { 42 vis[j]=1; 43 } 44 } 45 } 46 } 47 int main() 48 { 49 int T = in(); 50 int ii = 1; 51 init(); 52 while(T--) 53 { 54 ll area = in(),min_side = in(); 55 if(min_side >= sqrt(area)){ 56 printf("Case %d: %d ",ii++,0); 57 continue; 58 } 59 ll tmp = area; 60 int ans = 1; 61 for(int i = 0;i < p && prime[i]*prime[i] <= area;i++) 62 { 63 int cnt = 0; 64 while(area%prime[i] == 0) 65 { 66 area /= prime[i]; 67 cnt++; 68 } 69 ans *= (cnt+1); 70 } 71 if(area != 1) ans <<= 1; 72 ans >>= 1; //因数的个数除以二就是组数,同时排除了平方根 73 for(int i = 1;i < min_side;i++) 74 if(tmp%i == 0) ans--; //min_side此时是小于sqrt(area)的 75 printf("Case %d: %d ",ii++,ans); 76 } 77 return 0; 78 }
以上是关于C - Aladdin and the Flying Carpet的主要内容,如果未能解决你的问题,请参考以下文章
Aladdin and the Flying Carpet(唯一分解定理)
数论专题第三题 :C - Aladdin and the Flying Carpet
E - Aladdin and the Flying Carpet
LightOJ 1342 Aladdin and the Magical Sticks [想法题]
LightOJ 1341(Aladdin and the Flying Carpet )算术基本定理
Lightoj 1348 Aladdin and the Return Journey (树链剖分)(线段树单点修改区间求和)