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, ...
随机推荐
- DE1-SOC连接设定
将电源供应器插上电源接口. 使用白色的USB Type B线材将计算机与DE1-SoC上的USB-Blaster II接口连接.此接口主要负责FPGA配置以及HPS Debug使用. 使用Mini-U ...
- 关于jsonp(~~原理和理解)
JSON和JSONP 与XML相比,JSON是一个轻量级的数据交换格式.JSON对于JavaScript开发人员充满魅力的原因在于JSON本身就是Javascript中的对象. 例如一个ticker对 ...
- C# MVC 自学笔记—4 添加视图
==============================翻译============================== 在本节中,你将要修改 HelloWorldController 类,以便使 ...
- Codeforces 331A2 - Oh Sweet Beaverette (70 points)
贪心搞就行,用map记录每个数出现的下标,每次都取首尾两个.将中间权值为负的删掉后取sum值最大的就行. #include<iostream> #include<algorithm& ...
- Android实现异步处理 -- HTTP请求
原帖:http://www.cnblogs.com/answer1991/archive/2012/04/22/2464524.html Android操作UI的方法不是线程安全的,也就是说开发者自己 ...
- Image控件
前台代码: <asp:Image ID="Image1" runat="server" /> 后台代码; protected void Page_L ...
- BZOJ 1475: 方格取数( 网络流 )
本来想写道水题....结果调了这么久!就是一个 define 里面少加了个括号 ! 二分图最大点权独立集...黑白染色一下 , 然后建图 : S -> black_node , white_no ...
- 安装MyEclipse Color Themes
下载地址:http://eclipsecolorthemes.org/?list=toppicks&lang=html 安装步骤如下: 1.Import---Preferences 2.选择下 ...
- Cubieboard4卡片式电脑
Cubieboard4 also named CC-A80, is a open source mini PC or single board computer which has ultra-pow ...
- linux: 鸟哥的私房菜
鸟哥的私房菜 http://vbird.dic.ksu.edu.tw/linux_basic/0320bash.php