题解
【入门】甲乙的年龄
1 条题解
-
0
#include <bits/stdc++.h> using namespace std; bool ss(int n){//判断素数 bool f=true; for(int i=2;i<=sqrt(n);i++){ if(n%i==0){ f=false; break; } } if(n>1&&f){ return true; } else{ return false; } } int sum(int n){//数字之和 int s = 0; while(n != 0){ s = s + n % 10; n = n / 10; } return s; } int main(){ int j; //甲的年龄 for(int i = 1;i <= 100;i++){ j = i - 13;//乙的年龄 if((i+j)>=10 && (i+j)<99 && ss(i+j) && sum(i+j)==13){ cout<<i<<" "<<j<<endl; } } }
- 1