LightOJ 1341 Aladdin and the Flying Carpet(算术基本定理)
2015-09-19 00:02
441 查看
LightOJ 1341 Aladdin and the Flying Carpet
题意:
输入一个矩形面积,以及矩形边长的最小值,已知矩形不是正方形,求有多少种边长组合。思路:
转化一下就是求面积的所有正约数个数的一半,然后去掉有边长短于最小值以及正方形的情况就是最后答案。至于求约数个数,由算术基本定理可知:
n=pa11pa22...pakk那么,约数个数=(a1+1)(a2+1)...(ak+1)n=p_1^{a_1}p_2^{a_2}...p_k^{a_k}\\
那么,约数个数=(a_1+1)(a_2+1)...(a_k+1).
代码:
[code]/* * @author FreeWifi_novicer * language : C++/C */ #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<map> #include<set> #include<vector> #include<queue> using namespace std; #define clr( x , y ) memset(x,y,sizeof(x)) #define cls( x ) memset(x,0,sizeof(x)) #define pr( x ) cout << #x << " = " << x << endl #define pri( x ) cout << #x << " = " << x << " " #define test( t ) int t ; cin >> t ; int kase = 1 ; while( t-- ) #define mp make_pair #define pb push_back typedef long long lint; typedef long long ll; typedef long long LL; const int maxn = 1e6 + 47; bool noprime[maxn + 5] ; vector<int>p ; int sieve(){ cls( noprime ) ; p.clear(); for( int i = 2 ; i*i <= maxn ; i++ ) if( !noprime[i] ) for( int j = i * i ; j <= maxn ; j += i ) noprime[j] = true ; for( int i = 2 ; i <= maxn ; i++ ) if( !noprime[i] ) p.pb( i ) ; return p.size() ; } int calc( lint n , lint B , int len ){ lint res = 1 , tmp = n ; int i = 0 ; while( p[i] * p[i] <= n && i < len ) { lint cnt = 0 ; if( n % p[i] == 0 ){ while( n % p[i] == 0 ){ n /= p[i] ; cnt++ ; } } res *= cnt + 1 ; i++ ; } if( n > 1 ){ res <<= 1 ; } res >>= 1 ; n = tmp ; for( int i = 1 ; i < B ; i++ ) if( n % i == 0 ) res-- ; return res ; } int main(){ int len = sieve() ; test( t ){ lint a , b ; scanf( "%lld%lld" , &a , &b ) ; lint ans ; if( b * b >= a ){ ans = 0 ; } else ans = calc( a , b , len ) ; printf( "Case %d: %lld\n" , kase++ , ans ) ; } return 0; }
相关文章推荐
- C++基础知识(一)
- hadoop Secondary NameNode作用
- JS实现仿雅虎首页快捷登录入口及导航模块效果
- JS基于myFocus库实现各种功能的tab选项卡切换效果
- jQuery实现点击按钮弹出可关闭层的浮动层插件
- jquery实现点击弹出带标题栏的弹出层(从右上角飞入)效果
- JS+CSS实现简单滑动门(滑动菜单)效果
- jQuery实现单击弹出Div层窗口效果(可关闭可拖动)
- Linux上apache+svn创建多版本库
- 【转】读心术:硅谷创业公司正努力消灭语言
- 我们的信念
- 网站图片优化--怎么让网6站的图片为你“说话”
- JAVA: HOW TO AUTO-DETECT A FILE'S ENCODING
- 如何在阿里云生态下支持Spark?
- 【001】CentsOS 6.3 — 安装教程
- CentsOS 6.3 — 目录结构
- CentsOS 目录结构及常用命令
- CentsOS 6.3 — 安装bash-completion
- CentsOS 6.3 — Linux 终端快捷键
- Mysql语句 速成