继续做一下分解质因数的水题!

View Code

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <cstdlib>
  4 #include <cmath>
  5 #include <algorithm>
  6 #include <iostream>
  7
  8 #define debug 0
  9
 10 using namespace std;
 11
 12 typedef __int64 ll;
 13 const int maxn = 100005;
 14
 15 bool np[maxn];
 16 int pn, pr[maxn >> 2];
 17
 18 void gp(){
 19     memset(np, 0, sizeof(np));
 20     np[0] = np[1] = true;
 21     pn = 0;
 22     for (int i = 2; i < maxn; i++){
 23         if (!np[i]) pr[pn++] = i;
 24         for (int j = 0; j < pn && pr[j] * i < maxn; j++){
 25             np[pr[j] * i] = true;
 26             if (i % pr[j] == 0) break;
 27         }
 28     }
 29     #if debug
 30     printf("pn %d\n", pn);
 31     #endif
 32 }
 33
 34 void fac(int a, int *f, int *n, int &cnt){
 35     int i = 0;
 36
 37     cnt = 0;
 38     if (!a) return ;
 39     while (pr[i] * pr[i] <= a && i < pn){
 40         if (a % pr[i] == 0){
 41             f[cnt] = pr[i];
 42             n[cnt] = 0;
 43             while (a % pr[i] == 0) a /= pr[i], n[cnt]++;
 44             cnt++;
 45         }
 46         i++;
 47     }
 48     if (a != 1) f[cnt] = a, n[cnt++] = 1;
 49 }
 50
 51 int cnt_fac(int n, int f){
 52     int ep = f;
 53     int ret = 0;
 54
 55     while (ep <= n){
 56         ret += n / ep;
 57         ep *= f;
 58     }
 59
 60     return ret;
 61 }
 62
 63 bool deal(int a, int b){
 64     int f[30], cf[30];
 65     int n = 0;
 66
 67     memset(f, 0, sizeof(f));
 68     fac(a, f, cf, n);
 69     #if debug
 70     printf("n  %d\n\n", n);
 71     for (int i = 0; i < n; i++) {
 72         printf("%d  %d\n", f[i], cf[i]);
 73     }
 74     f[n] = 0;
 75     #endif
 76
 77     for (int i = 0; i < n; i++) {
 78         #if debug
 79         printf("fac %d  num %d\n", f[i], cnt_fac(b, f[i]));
 80         #endif
 81         if (cf[i] > cnt_fac(b, f[i])) {
 82             return false;
 83         }
 84     }
 85     return true;
 86 }
 87
 88 int main(){
 89     int a, b;
 90
 91     gp();
 92     while (~scanf("%d%d", &a, &b)){
 93         if (deal(b, a) && b) {
 94             printf("%d divides %d!\n", b, a);
 95         }
 96         else {
 97             printf("%d does not divide %d!\n", b, a);
 98         }
 99     }
100
101     return 0;
102 }

 

——written by Lyon

转载于:https://www.cnblogs.com/LyonLys/archive/2012/08/05/poj_2649_Lyon.html

poj 2649 Factovisors相关推荐

  1. POJ 3268 D-Silver Cow Party

    http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  2. poj 2559 Largest Rectangle in a Histogram 栈

    // poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...

  3. POJ 2528 Mayor's posters(线段树)

    题目大意 贴海报.每张海报的高度都是一样的,唯独宽度不一样.每张海报只能占用整数倍的单位线段长度,贴了 n(n<=10000) 张海报之后,有几张能够看见(有一个角能看见这张海报也算被看见了)? ...

  4. POJ 2226 Muddy Fields 最小点覆盖+加建图(好题)

    题目链接 题目一看就是最小点覆盖,这道题与POJ - 3041 算是一类题,但是3041算是一道十分裸的,因为删除的是整行或者整列,所以图其实是现成的,但是本题的难点就在如何建图. 思路:首先还是尽量 ...

  5. poj 2681 字符串

    http://poj.org/problem?id=2681 给你任意长度的字符串,找出两串字符中不相同的字符个数(总数) #include<string> #include<cst ...

  6. (区间dp 或 记忆化搜素 )Brackets -- POJ -- 2955

    http://poj.org/problem?id=2955 Description We give the following inductive definition of a "reg ...

  7. POJ 2586 Y2K Accounting Bug(贪心)

    题目连接:http://poj.org/problem?id=2586 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D.公司每五个月进行一次统计,全年共统计8次( ...

  8. poj 2362 Square

    #include <iostream> //参照poj 1011 sticks#include <algorithm>using namespace std;int stick ...

  9. 图论之拓扑排序 poj 2367 Genealogical tree

    题目链接 http://poj.org/problem?id=2367 题意就是给定一系列关系,按这些关系拓扑排序. #include<cstdio> #include<cstrin ...

  10. 二分搜索 POJ 2456 Aggressive cows

    题目传送门 1 /* 2 二分搜索:搜索安排最近牛的距离不小于d 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #incl ...

最新文章

  1. numpy使用diagonal函数和sum函数计算矩阵的迹(trace)、使用T函数对矩阵进行转置(transpose matrix)
  2. 锋利的jquery 知识点总结
  3. python数据预测_python时间序列预测股票走势
  4. 前端学习(2515):父向子传值
  5. jquery-等待加载-显示隐藏-遍历
  6. C语言课后习题(1)
  7. checkbox,全选和反选的功能
  8. /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.12‘ not found解决办法
  9. python开发k8s管理平台_运维开发和k8s运维如何选择,请各位大神指导一下?
  10. ubuntu的文件路径
  11. 本科毕业论文降低查重率小技巧
  12. 如何将桌面上的计算机图表隐藏,怎么把电脑桌面隐藏图标弄出来怎么办
  13. 北大医学英语和计算机,医学英语专业本科生张泉同学在SSCI期刊发表论文
  14. IGBT芯片赛道竞争激烈,水光半导体Wassersun推出全新IGBT制程技术
  15. html5 右侧客服代码,简洁右侧栏客服代码
  16. Simpson积分应用
  17. c++ primer kindle_kindle全系列使用墨水屏版微信读书解决方法,你的无限卡有用了...
  18. 某公司要开发新游戏,请用面向对象的思想,设计游戏中的蛇怪和蜈蚣精
  19. HTTP Live Streaming 分析
  20. 400 (Bad Request)错误的解决方法

热门文章

  1. mfc 鼠标移动到 button上面时 背景颜色改变_Python3与PyQt5编程示例:实现颜色拾取器小工具...
  2. java核心技术卷一 基础知识读书笔记
  3. 遇见Flask-Script
  4. [总结] LCT学习笔记
  5. Java开发学习教程之对象的创建与使用
  6. #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’
  7. Font Awesome图标字体
  8. 2、HTML 元素属性
  9. Google Maps API 进级: GPolygon对象2
  10. 使用gson和fastjson来解析json