top1编程
← 返回题目
题解

【基础】同构数

3 条题解

  • 0
    @ 2026-7-29 20:24:14
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n, count = 0;
    	cin >> n;
    	for (int i = 1; i <= n; i++) {
    		int k = 10;
    		for (int j = 0; j < 5; j++) {
    			if (i == i * i % k) {
    				count++;
    				break;
    			}
    			k *= 10;
    		}
    	}
    	cout << count;
    	return 0;
    }
    
    • 0
      @ 2026-7-29 0:06:24
      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      	int n, count = 0;
      	cin >> n;
      	for (int i = 1; i <= n; i++) {
      		int k = 10;
      		for (int j = 0; j < 5; j++) {
      			if (i == i * i % k) {
      				count++;
      				break;
      			}
      			k *= 10;
      		}
      	}
      	cout << count;
      	return 0;
      }
      
      • 0
        @ 2026-7-28 22:09:49
        #include<bits/stdc++.h>
        using namespace std;
        int main(){
        	int n,s=0;
        	cin>>n;
        	for(int i=1;i<=n;i++){
        		if(i*i%10==i||i*i%100==i||i*i%1000==i||i*i%10000==i||i*i%100000==i||i*i%1000000==i){
        			s++;
        		}
        	}
        	cout<<s;
        	return 0;
        }
        
        • 1