Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
You are given positive integers X and Y. If there exists a positive integer not greater than 1018 that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print −1.
Constraints
- 1≤X,Y≤109
- X and Y are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print a positive integer not greater than 1018 that is a multiple of X but not a multiple of Y, or print −1 if it does not exist.
Sample Input 1
Copy
8 6
Sample Output 1
Copy
16
For example, 16 is a multiple of 8 but not a multiple of 6.
Sample Input 2
Copy
3 3
Sample Output 2
Copy
-1
A multiple of 3 is a multiple of 3.
只需要判断x是否是y的倍数。
代码:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iomanip> using namespace std; int a,b; int main() { cin>>a>>b; if(a % b)cout<<a; else cout<<-1; }