Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- using namespace std;
- char ys[9] = {0};
- int mgs[3] = {0};//分解每个数
- int module = 0;//余数
- int x = 0;//三位数真实的 021=21
- int s = 0;
- bool checkprime(int a) {
- for (int i = 2; i>=0; i--) {
- module = a;
- mgs[i] = a % 10;
- module = a / 10;
- }
- if (mgs[0] != 0) {//百位不为0
- for (int i = 2; i < a; i++) {
- if (a % i == 0) {
- return false;
- }
- }
- }
- else if (mgs[0] == 0) {//百位为0
- if (mgs[1] == 0) {//十位为0
- if (mgs[2] == 0) {//个位为0
- return false;
- }
- else if (mgs[2] == 1) {//个位为1
- return false;
- }
- else {//个位不为1
- for (int i = 2; i < mgs[2]; i++) {
- if (mgs[2] % i == 0) {
- return false;
- }
- }
- }
- }
- else {//百位为0 十不为0
- x = mgs[2] + mgs[1] * 10;
- for (int i = 2; i < x; i++) {
- if (x % i == 0) {
- return false;
- }
- }
- }
- }
- return true;
- }
- bool checksqrt(int a) {
- for (int i = 2; i>=0; i--) {
- module = a;
- mgs[i] = a % 10;
- module = a / 10;
- }
- if (mgs[0] != 0) {
- s = sqrt(a);
- if (s * s == a) {
- return true;
- }
- else {
- return false;
- }
- }
- else if (mgs[0] == 0) {
- if (mgs[1] == 0) {
- if (mgs[2] == 0) {
- return false;
- }
- else {
- s = sqrt(mgs[2]);
- if (s * s == a) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- else {
- x = mgs[2] + mgs[1] * 10;
- s = sqrt(x);
- if (s * s == x) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- }
- bool check(int m) {
- for (int i = 1; i<=9; i++) {
- ys[i] = m % 10;
- if (ys[i] == 3) {
- if ((m / 10) % 10 == 1) {
- return true;
- }
- }
- m = m / 10;
- }
- return false;
- }
- int main() {
- char a[10] = { 0 };
- char b[10] = { 0 };
- int m, n;
- cin >> m >> n;
- int front = 0;
- int back = 0;
- int flag = 0;
- for (int i = m; i <= n; i++) {
- front = i / 1000000;
- if (!checkprime(front)) {
- continue;
- }
- back = i % 1000;
- if (!checksqrt(back*1.0)) {
- continue;
- }
- if (check(i)) {
- continue;
- }
- flag++;
- }
- cout << flag << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement