【lightoj】1014 - Ifter Party

1014 - Ifter Party
Time Limit: 2 second(s)Memory Limit: 32 MB

I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited C contestants and arranged P piaju's (some kind of food, specially made for Ifter). Each contestant ate Q piaju's and L piaju's were left (L < Q).

Now you have to find the number of piaju's each contestant ate.

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 of possible 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

 题意:有p克蛋糕,每人吃q克,剩余l克,问q的值有多少种情况,从小到大输出   也就是求p-l的所有大于l的因数

         int数组会超时。。

code:

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std ;
  4. #include<cmath>
  5. #include<vector>
  6. vector < int >v ;
  7. int main ( )
  8. {
  9.     int t ;
  10.     long long p,l ;
  11.     scanf ( "%d", &t ) ;
  12.     int k = 1 ;
  13.     while (t -- )
  14.     {
  15.         v. clear ( ) ;
  16.         scanf ( "%lld%lld", &p, &l ) ;
  17.         long long q ;
  18.         q =p -l ;
  19.         int m = ( int ) sqrt (q ) ;
  20.         for ( long long i = 1 ;i <=m ;i ++ )
  21.         {
  22.             if (q %i == 0 ) {
  23.                 if (i >l ) v. push_back (i ) ;
  24.                 if (q /i ! =i &&q /i >l ) v. push_back (q /i ) ;
  25.             }
  26.            
  27.         }
  28.         if (v. empty ( ) ) printf ( "Case %d: impossible\n",k ++ ) ;
  29.         else {
  30.             printf ( "Case %d:",k ++ ) ;
  31.         sort (v. begin ( ),v. end ( ) ) ; int s =v. size ( ) ;
  32.         for ( int i = 0 ;i <s ;i ++ )
  33.         printf ( " %d",v [i ] ) ; printf ( "\n" ) ;
  34.         }
  35.        
  36.     }
  37.     return 0 ;
  38.   }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值