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, ...
随机推荐
- bootstrap base css 基本css
Headings All HTML headings, <h1> through <h6> are available. h1. Heading 1 h2. Heading 2 ...
- perl 安装 ZooKeeper模块
1072 ./configure --libdir=/usr/lib 1073 make 1074 make install 1075 cpan ZooKeeper [root@wx03 c]# pe ...
- 基于visual Studio2013解决算法导论之023队列实现(基于数组)
题目 基于数组的队列 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> #i ...
- iOS开发- 获取精确剩余电量
[UIDevice currentDevice].batteryMonitoringEnabled = YES; double deviceLevel = [UIDevice currentDevic ...
- PHP - 四级单词lrc文件解析为txt
原始文件: 转换后文件: php代码: 首先根据需要更改文件路径. 转换后存放的文件要事先创建,为txt文件. 核心代码:正则表达式替换: <?php header('Content-type: ...
- [转载] iOS开发分辨率那点事
1 iOS设备的分辨率 iOS设备,目前最主要的有3种(Apple TV等不在此讨论),按分辨率分为两类 iPhone/iPod Touch 普屏分辨率 320像素 x 480像素 Retina ...
- first-,second- and third-class value
In computer science, a programming language is said to have first-class functions if it treats funct ...
- GDSOI2015 task2 覆盖半径
题目大意 一个\(n\times m\)的矩阵中有\(p\)个已经确定圆心的圆,并且每个格子有一定的分数,如果一个格子被任意一个或以上的圆覆盖,那么就可以得到这个格子的分数.现在求最小的半径,使得得分 ...
- ajaxSubmit提交文件表单不执行success
先描述一下我遇到的问题,系统里所有的表单都用ajaxSubmit来提交,成功回调success函数,普通表单都是没有问题的,但是有文件上传的表单就不行了,不会回调success,经验证会回调compl ...
- poj 1155 TELE (树形背包dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: poj-1155 题意 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构, ...