Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("countprimsub.in");
- ofstream fout("countprimsub.out");
- int n,x, s[1001], d[1001],info[1001];
- int prim(int n)
- {
- if(n==0 || n==1)
- return 0;
- else
- if(n%2==0&&n!=2)
- return 0;
- else
- for(int d=3;d*d<=n;d=d+2)
- if(n%d==0)
- return 0;
- return 1;
- }
- int count(int k)
- {
- if(k==0) return 0;
- else
- {
- if(prim(info[k]))
- return 1+count(s[k])+count(d[k]);
- else
- return count(s[k])+count(d[k]);
- }
- }
- int main()
- {
- fin>>n;
- for(int i=1;i<=n;i++)
- fin>>info[i]>>s[i]>>d[i];
- int k,y;
- fin>>k;
- for(int i=1;i<=k;i++)
- {
- fin>>y;
- fout<<count(y)<<'\n';
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement