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 ...
随机推荐
- 2437: [Noi2011]兔兔与蛋蛋 - BZOJ
Description Input 输入的第一行包含两个正整数 n.m.接下来 n行描述初始棋盘.其中第i 行包含 m个字符,每个字符都是大写英文字母"X".大写英文字母" ...
- Uyuw's Concert POJ2451
裸半平面交,以前没写过,先写一遍再说 我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多4条边,就WA了) const maxn=; eps=1e-7; type point=r ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...
- AlphaToCoverage solution
After msaa output the alpha in ps remove clip in ps in blendstate add AlphaToCoverageEnable = TRUE - ...
- memcached+php客户端
连接memcached <?php $mem = new Memcache; $mem->connect('localhost',11211) or die("connected ...
- iOS开发之深入探讨runtime机制01-类与对象
最近有个同事问我关于“runtime机制”的问题,我想可能很多人对这个都不是太清楚,在这里,和大家分享一下我对于runtime机制的理解.要深入理解runtime,首先要从最基本的类与对象开始,本文将 ...
- ubuntu下hadoop2.6在eclipse上的配置
1.复制hadoop-eclipse-plugin-2.6.0.jar插件到eclipse的plugins目录下(hadoop2.6的插件,在hadoop自带上没有,要上网下载,多试几个 如果是从ub ...
- 超实用js代码段一
1: 过滤首尾空格trim.2:过滤左边空格ltrim 3:过滤右边空格 一:用正则方法写成三个函数. <script type="text/javascript" ...
- *[hackerrank]Jim Beam
https://www.hackerrank.com/contests/infinitum-aug14/challenges/jim-beam 学习了线段相交的判断法.首先是叉乘,叉乘的几何意义是有向 ...
- eclipse安装反编译插件
1. 进入http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download 下载 net.sf.jadclipse ...