uvaIrrelevant Elements
唯一分解定理。
可以看出在最后每个a的系数是杨辉三角的第n行。
但是不能递推,否则会tle。
就从C(n-1,0)开始乘n-k再除以k。记录下每个的系数,如果该项系数小于m就代表和答案有关。
代码里的ok为true时,代表和答案有关。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn = 100000 + 10; bool ok[maxn];
int n,m;
int e[maxn],prime[maxn],cnt,num;
int ans[maxn]; void init(int n) {
memset(e,0,sizeof(e)); cnt=0; num=0;
int m = (int) sqrt(n);
for(int i=2;i<=m;i++) if(n%i==0) {
prime[++cnt]=i;
while(n%i==0) {
e[cnt]++;
n/=i;
}
}
if(n>1) {
prime[++cnt]=n;
e[cnt]=1;
}
} int main() {
while(scanf("%d%d",&n,&m)==2) {
init(m);
memset(ok,0,sizeof(ok));
for(int i=1,h;i<=cnt;i++) {
int res=0;
for(int k=1,x;k<n;k++) {
x=n-k;
while(x%prime[i]==0) {
x/=prime[i];
res++;
}
x=k;
while(x%prime[i]==0) {
x/=prime[i];
res--;
}
if(res<e[i]) ok[k]=1;
}
}
for(int i=1;i<n;i++) if(!ok[i])
ans[++num]=i;
printf("%d\n",num);
if(num) {
for(int i=1;i<num;i++)
printf("%d ",ans[i]+1);
printf("%d",ans[num]+1);
}
printf("\n");
}
return 0;
}
uvaIrrelevant Elements的更多相关文章
- js Form.elements[i]的使用实例
function pdf(){ //一个html里面可能存在多个form,所以document.form[0]指的是第一个form,document.form[1]返回就是第二个form,如果没 ...
- View and Data API Tips: Hide elements in viewer completely
By Daniel Du With View and Data API, you can hide some elements in viewer by calling "viewer.hi ...
- [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二
Given a non-empty integer array, find the minimum number of moves required to make all array element ...
- [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等
Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...
- [LeetCode] Top K Frequent Elements 前K个高频元素
Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...
- [LeetCode] Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- Chrome 开发工具之Elements
友情提示:全文图片高能,如使用手机阅读,请确保在wifi情况下或者流量充足.图片有点渣,也算辛苦做出来的,请别嫌弃- Elements面板主要展示当前页面的组织结构,在如今的应用程序中,HTML页面初 ...
- T-SQL Recipes之Separating elements
Separating elements Separating elements is a classic T-SQL challenge. It involves a table called Arr ...
- POJ2167Irrelevant Elements[唯一分解定理 组合数 杨辉三角]
Irrelevant Elements Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2407 Accepted: 59 ...
随机推荐
- oracle 建立主键与索引【转】
此文转自:http://blog.sina.com.cn/s/blog_439f80c4010094n1.html 创建主键: alter table T add primary key (V) T是 ...
- 1996: [Hnoi2010]chorus 合唱队 - BZOJ
Description Input Output Sample Input41701 1702 1703 1704Sample Output8HINT 水题,区间dp,f[l,r,k]表示区间[l,r ...
- UVA 10720 Graph Construction 贪心+优先队列
题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vert ...
- 安装JDK后JRE与JVM联系浅谈
转自安装JDK后JRE与JVM联系浅谈 安装JDK后JRE.JVM之间的关系是什么呢?那么我们要从安装JDK慢慢说起. 如果安装了JDK,会发同你的电脑有两套JRE: 一套位于 <JDK安装目录 ...
- Oracle session连接数和inactive的问题记录
Oracle session连接数和inactive的问题记录 http://timnity.javaeye.com/blog/280383 从上周起,服务器Oracle数据库出现问题,用不到半天,就 ...
- HDOJ-1999 不可摸数
不可摸数 转自:http://www.cnblogs.com/dongsheng/archive/2012/08/18/2645594.html Time Limit: 2000/1000 MS (J ...
- HDU 3397 Sequence operation (区间合并,操作比较多)
费了我一天半的时间,到处debug,后来才发现,主要是建树的时候只在叶子节点对lazy1和lazy2进行初始化了,父节点都没初始化...晕. 具体见代码吧. #include <iostream ...
- Jquery+Jquery-easyui的倒计时
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Win7 64 安装Visual Studio 2010和SQL Server 2008 R2
1. 在MSDN,我告诉你下载安装文件,VS 2010 不论32位还是64位都是同一个文件,cn_visual_studio_2010_ultimate_x86_dvd_532347.iso.SQL下 ...
- 关于JS中变量的作用域-实例
先看问题,如下,自己运行一下吧! if (!('_qyzA' in window)) { var _qyzA = 1; } alert(_qyzA);//undefined 分析:首先,所有的全局变量 ...