FOJ 1607 Greedy division 数学题
题目地址: http://acm.fzu.edu.cn/problem.php?pid=1607
给定一个n,将n平均分成m份,问有几种方法,每种方法中找出最大的数。思路:就是求n的因子数、先将每个数求出最小素因子、再将n的所有素因子数加1相乘。小结论:求一个数的所有因子数、先分解、n=(a^x)*(b^y)*(c^z),(a、b、c均为素数),因子数=(x+1)*(y+1)*(z+1)-1。
AC代码:输入数据很多,开始用cin果断超时了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cfloat>
using namespace std; typedef long long LL;
const int N=1000005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); int n,Min[N];//每一个数的最小质因数 void MIN()
{
int i,j;
for(i=2;i<N;i+=2)
{
Min[i]=2;
Min[i-1]=0;
}
for(i=3;i<N;i++)
{
if(Min[i]==0)
{
Min[i]=i;
if(i>sqrt(N*1.0)) continue;//防止越界
for(j=i*i;j<N;j+=i)
if(Min[j]==0)
Min[j]=i;
}
}
} void xiaohao()
{
int i,j,p=n,sum=1;
while(p>1)
{
int cnt=1,k=Min[p];
while(p%k==0)
{
cnt++;
p/=k;
}
sum*=cnt;
}
printf("%d %d\n",sum-1,n/Min[n]);
} int main()
{
MIN();
while(scanf("%d",&n)!=EOF)
{
xiaohao();
}
return 0;
}
FOJ 1607 Greedy division 数学题的更多相关文章
- FUzhou 1607 Greedy division---因子个数问题。
Problem 1607 Greedy division http://acm.fzu.edu.cn/problem.php?pid=1607 Accept: 402 Submit: 1463T ...
- Polynomial Division 数学题
https://www.hackerrank.com/contests/101hack45/challenges/polynomial-division 询问一个多项式能否整除一个一次函数.a * x ...
- C. Greedy Arkady
kk people want to split nn candies between them. Each candy should be given to exactly one of them o ...
- 水题挑战6: CF1444A DIvision
A. Division time limit per test1 second memory limit per test512 megabytes inputstandard input outpu ...
- python from __future__ import division
1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- [LeetCode] Evaluate Division 求除法表达式的值
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- 关于分工的思考 (Thoughts on Division of Labor)
Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...
- Windows 10一周年更新正式版官方ISO镜像(1607)
微软已经开始推送Win10一周年更新正式版系统,按照此前预告微软官方网站也同步推出了Win10一周年更新正式版ISO官方镜像下载,版本已经升级到最新的1607,也就是Win10 Build 1607, ...
随机推荐
- Socket网络编程--FTP客户端(60篇socket博客,而且都比较简单、深入浅出)
已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解FTP作用 就是一个提供一个文件的共享协议. 1.了解FTP协议 ...
- 基于visual Studio2013解决C语言竞赛题之0418位数操作
题目 解决代码及点评 /************************************************************************/ /* 18. 给 ...
- 解决 RichTextBox 文件格式不对问题
RichTextBox文件格式不对: 原因:富文本框的LoadFile方法只支持RTF格式的文件或者标准的ASCII文本本档,,我们一般的文本文档是ANSI或者UTF-8的格式,所以,报这个错. 解决 ...
- RadioButton控件
前台代码: <div> <asp:RadioButton ID="RadioButton1" runat="server" GroupName ...
- TOMCAT的域名配置
链接地址:http://blog.163.com/skk1987@126/blog/static/29303413201051383548377/ 现在很多的公司的网站都是用tomcat作为应用服务区 ...
- ZOJ3768 夹逼查找【STL__lower_bound()_的应用】
首先学习一下lower_bound() 函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置.如果所有元素都小于val,则返回last ...
- Android 判断当前线程是否为主线程
public static boolean isInMainThread() { return Looper.myLooper() == Looper.getMainLooper(); }
- Android开发--CardView使用
Android5.0中向我们介绍了一个全新的控件–CardView,从本质上看,可以将CardView看做是FrameLayout在自身之上添加了圆角和阴影效果.请注意:CardView被包装为一种布 ...
- shell中exec解析(转)
参考:<linux命令.编辑器与shell编程> <unix环境高级编程> exec和source都属于bash内部命令(builtins commands),在bash下输入 ...
- Android 它们的定义View它BounceProgressBar
转载请注明出处:http://blog.csdn.net/bbld_/article/details/41246247 [Rocko's blog] 之前几天下载了非常久没用了的桌面版酷狗来用用的时候 ...