LightOJ 1014 - Ifter Party (**求因子)
来源:互联网 发布:路旁的叶修写真集淘宝 编辑:程序博客网 时间:2024/06/05 14:14
I have an Ifter party at the 5th day ofRamadan for the contestants. For this reason I have invitedCcontestants and arrangedP piaju's (some kind of food, specially madefor Ifter). Each contestant ateQ piaju's andL piaju's were left(L < Q).
Now you have to find the number of piaju's each contestantate.
Input
Input starts with an integer T (≤ 325),denoting the number of test cases.
Each case contains two non-negative integers P and L(0 ≤ L < P < 231).
Output
For each case, print the case number and the number ofpossible integers in ascending order. If no such integer is found print'impossible'.
Sample Input
Output for Sample Input
4
10 0
13 2
300 98
1000 997
Case 1: 1 2 5 10
Case 2: 11
Case 3: 101 202
Case 4: impossible
题意:有C个人,然后给他们P个食物,每个人吃Q个,然后剩下L个,求Q可能的情况
思路:其实一看直接暴力枚举就行了,复杂度sqrt(n),但是这道题岂会那么简单,如果枚举过后直接sort定会TLE,所以说要姿势了,将能整除的存起来,然后后面判断,倒序判断,加上中间的剪枝,终于过了。。。
总结:各种TLE,优先队列,小数组sort什么的都用上了,还是TLE,无语。。然后就xjb搞搞出来个这个方法,过了。
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 1001000#define LL long long#define ll __int64#define INF 0x7fffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define eps 1e-10using namespace std;int gcd(int a,int b){return b?gcd(b,a%b):a;}int lcm(int a,int b){return a/gcd(a,b)*b;}LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}//headint ans[MAXN];int main(){ int t,p,l,i; int cas=0; scanf("%d",&t); while(t--) { scanf("%d%d",&p,&l); int num=p-l; int bz=0;int cnt=0; printf("Case %d:",++cas); if(num<=l) { printf(" impossible\n"); continue; } for(i=1;i<=(int)sqrt(num);i++) { if(num%i==0) { ans[cnt++]=i; if(i>l) bz=1; if(num/i>l) bz=1; } } if(bz==0) { printf(" impossible\n"); continue; } for(i=0;i<cnt;i++) if(ans[i]>l) printf(" %d",ans[i]); if(ans[cnt-1]*ans[cnt-1]==num) cnt--; for(i=cnt-1;i>=0;i--) if(num/ans[i]>l) printf(" %d",num/ans[i]); printf("\n"); } return 0;}
- LightOJ 1014 - Ifter Party (**求因子)
- LightOJ 1014 Ifter Party 分解因子
- LightOJ 1014 Ifter Party
- LightOJ-1014-Ifter Party
- Ifter Party LightOJ
- Light OJ 1014 Ifter Party [因子分解]【数论】
- 1014 - Ifter Party
- 1014 - Ifter Party
- Light OJ 1014 - Ifter Party
- Light oj 1014 - Ifter Party
- LightOJ1014 Ifter Party
- lightoj 1014 求一个数的所有因子
- LightOJ 1035 - Intelligent Factorial Factorization (求因子)
- LightOJ 1028 1028 - Trailing Zeroes (I) (求因子个数)
- LightOJ 1054 - Efficient Pseudo Code (求n^m的因子和)
- LightOJ 1028 求n的因子的个数
- HDU2521(求因子个数)
- poj2992(求因子个数)
- java中形参长度可变的方法
- CURL模拟POST请求实例
- Yaf安装及配置
- HDU——1019Least Common Multiple(多个数的最小公倍数)
- 开源爬虫
- LightOJ 1014 - Ifter Party (**求因子)
- 了解套接字Socket
- html需要掌握的几个全局属性
- JavaScript的this分别代表什么
- 用户爬虫例子
- 爬虫基本知识
- 电脑如何连接万能钥匙解开的WiFi
- mysql_real_escape_string总是返回false
- cf#AIM Tech D. Array GCD (数学+枚举)