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, ...
随机推荐
- 数据结构C语言版 表插入排序 静态表
数据结构C语言版 表插入排序.txt两个人吵架,先说对不起的人,并不是认输了,并不是原谅了.他只是比对方更珍惜这份感情./* 数据结构C语言版 表插入排序 算法10.3 P267-P270 编译 ...
- 创建.NET Core项目
创建.NET Core项目 ? 对于.NET开发人员来说,我们已经习惯了VS这个世界上最强大的IDE,所以对他们来说,项目的创建直接利用安装到VS中相应的项目模板即可.当.NET Core跨出了Win ...
- 简单实用的下拉菜单(CSS+jquery)
原文 简单实用的下拉菜单(CSS+jquery) 没什么可以说的,直接上例子 html+jquery代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...
- JavaScript 的数组操作--删除元素
在JavaScript中,可以很方便的删除指定位置的元素,这个是用到 splice方法, 该方法用于删除或替换数组中的部分数据. 其语法定义是 : splice(start , count [,new ...
- Use Node.js DDP Client on Arduino Yun to Access Meteor Server
Use Node.js DDP Client on Arduino Yun to Access Meteor Server 概述 在Arduino Yun上安装 Node.js, 并測试与 Meteo ...
- UVA 10041 (13.08.25)
Problem C: Vito's family Background The world-known gangster Vito Deadstone is moving to New York. ...
- C# this关键字
使用方式之一: this,在构造函数中使用. 当使用构造函数的重载时,可使用this关键字. //构造函数-重载 public Student(int id, string name, int age ...
- 使用CDN对动态网站内容加速有效果吗
个资源文件,有利于减少原始服务器的压力. 缓存网页内容 对于动态网站而言,部分访问量大的网页内容可能改观不大,好比论坛的首页,置顶的帖子很少泛起大转变,因此这样的网页可 ...
- Convert SVG to PNG in Python - Stack Overflow
Convert SVG to PNG in Python - Stack Overflow Convert SVG to PNG in Python
- Login oracle for external authenticate
Generally, we can login the oracle by os authentication, if we login os in a remote machine and make ...