codeforces 177B2 B2. Rectangular Game(数论)
来源:互联网 发布:tw域名查询 编辑:程序博客网 时间:2024/04/29 07:53
题目链接:
codeforces 177B2
题目大意:
给出n个点,每次排成a*b的矩形,每次留下b个,重新排,每次操作后剩下的点数的和最大是多少。
题目分析:
每次只需要将当前数的最小的质因数作为行数,这样能够保证剩下的最多,导致最终的结果最大。
AC代码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <vector>#define MAX 100007using namespace std;typedef long long LL;int mark[MAX],n;vector<int> p;void init ( ){ p.push_back ( 2 ); memset ( mark , -1 , sizeof ( mark )); for ( int i = 3 ; i < MAX ; i++ ) { if (~mark[i]) continue; p.push_back ( i ); for ( int j = 2*i ; j < MAX ; j += i ) mark[j] = i; }}int main ( ){ init (); int m = p.size(); while (~scanf ( "%d" , &n )) { LL ans = 1; while ( n != 1 ) { int pp = -1; for ( int i = 0; i < m && p[i]*p[i] <= n; i++ ) { if ( n%p[i] ) continue; pp = p[i]; break; } if ( pp == -1 ) pp = n; ans += n; n /= pp; } printf ("%d\n" , ans ); }}
0 0
- codeforces 177B2 B2. Rectangular Game(数论)
- b2
- B2
- Codeforces 395 B2. iwiwi
- Codeforces 316B2 EKG
- Codeforces 513B2 Permutations
- CodeForces 617B2
- Codeforces 513B2 - Permutations (思维)
- codeforces——395B2——B2. iwiwi
- codeforces ABBYY Cup 3.0 - Finals (online version) B2. Shave Beaver!
- Codeforces 513B2 or 513B1 Permutations 策略题
- 没评上B2
- UVa 11063 - B2-Sequence
- (513B2)codeforce
- 山西省蓝桥杯B2
- 营养与维生素B2
- 营养与维生素B2
- 二分贪心练习题-B2
- Android Studio 插件安装(以GsonFormat为例)
- Undraw the Trees
- java中abstract怎么使用
- UVa 1513 / UVALive 5902 Movie collection (树状数组)
- shell里面的test用法
- codeforces 177B2 B2. Rectangular Game(数论)
- hdu 2066 一个人的旅行-spfa
- 【转】Handler有可能引起内存溢出
- new InitialContext() 创建ejb实例的过程
- 亿级Web系统搭建——单机到分布式集群
- VS错误 FileTracker : error FTK1011:
- android--textView添加html超链接响应
- SQLAlchemy 学习(一)
- Android中Drawable分类汇总(上)