Title:
lulu likes positive integers less than or equal to 1000, but if a number is a multiple of a or b, lulu will hate it. If a number contains numbers a and b, lulu will hate it. (for example, a=14, b=23. If a number contains any one of the four numbers 1, 2, 3, 4, lulu will hate this number.). Now tell you a, b. can you tell how many lulu likes.
Input:
The first line is the sample number T
Lines 2 to 2+T-1 have 2 integers a b per line.
Output:
Output the number of likes of lulu
Sample Input:
3
2 3
14 23
1234 5678
Sample Output:
171
190
7
Title Link
Idea: divide each digit of two numbers and mark all the numbers in the range
AC Code:
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
bool Judge[10] = {0}; // Judge which numbers are included in the two input numbers with judge
int d[5] = {10,100,1000,10000,100000}; // Using d array to get every digit
bool IsLike[1010]; // Type the number you don't like
int a,b; // Two numbers entered
void _Judge(int x,int y) { // _The Judge function determines which numbers are included in the two input numbers
mem(Judge, 0); // Initializing an array containing elements
for (int i = 0;i < 5;++i) { // Loop extraction per digit
int a1 = a,b1 = b; // Extraction using intermediate variables a1,b1
if (a >= d[i]) {
a1 /= d[i];
}
if (b > d[i]) {
b1 /= d[i];
}
a1 %= 10;
b1 %= 10;
Judge[a1] = 1; // Mark the extracted number
Judge[b1] = 1;
}
}
void Like() { // Like function to table IsLike array
mem(IsLike, 0); // Initializing the print table array
for (int i = 0;i < 1010;++i) { // Ergodic tabulation
if (i % a == 0 || i % b == 0) { // Judge the division condition
IsLike[i] = 1; // If divisible, print the table to continue the next number of cycles
continue;
}
for (int j = 0;j < 3;++j) { // Loop to determine whether it contains the number in the input number
int judgeLike = i;
if (i >= d[j]) {
judgeLike /= d[j];
}
judgeLike %= 10;
if (Judge[judgeLike] == 1) { // If it contains, print the table to continue the next number of cycles
IsLike[i] = 1;
break;
}
}
}
}
int main() {
// Acceleration I / O
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T; // Enter number of test groups
while (T--) {
cin >> a >> b;
_Judge(a,b); // Extract per digit
Like(); // charge by the meter
ll sum = 0;
for (int i = 1;i <= 1000;++i) { // The number of likes not marked in the circular statistics table
if (IsLike[i] == 0) {
sum++;
}
}
cout << sum << endl; // output
}
return 0;
}