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:
- #include<cstdio>
-
#include<algorithm>
-
using namespace std ;
-
#include<cmath>
-
#include<vector>
-
vector < int >v ;
-
int main ( )
-
{
-
int t ;
-
long long p,l ;
-
scanf ( "%d", &t ) ;
-
int k = 1 ;
-
while (t -- )
-
{
-
v. clear ( ) ;
-
scanf ( "%lld%lld", &p, &l ) ;
-
long long q ;
-
q =p -l ;
-
int m = ( int ) sqrt (q ) ;
-
for ( long long i = 1 ;i <=m ;i ++ )
-
{
-
if (q %i == 0 ) {
-
if (i >l ) v. push_back (i ) ;
-
if (q /i ! =i &&q /i >l ) v. push_back (q /i ) ;
-
}
-
-
}
-
if (v. empty ( ) ) printf ( "Case %d: impossible\n",k ++ ) ;
-
else {
-
printf ( "Case %d:",k ++ ) ;
-
sort (v. begin ( ),v. end ( ) ) ; int s =v. size ( ) ;
-
for ( int i = 0 ;i <s ;i ++ )
-
printf ( " %d",v [i ] ) ; printf ( "\n" ) ;
-
}
-
-
}
-
return 0 ;
-
}