Pagini recente » Cod sursa (job #425006) | Cod sursa (job #123178) | Cod sursa (job #2612198) | Cod sursa (job #886295) | Cod sursa (job #672588)
Cod sursa(job #672588)
#include<iostream>
#include<fstream>
using namespace std;
ifstream ifile;
ofstream ofile;
int i,j,k,n,u,v,cont=0;
struct Nod{
Nod *next;
double val;
};
bool notIn(Nod *&u, double x){
int ok;
Nod *r;
r=u;
ok=1;
while(r!=NULL && ok)
{
if(x==r->val) ok=0;
else r=r->next;
}
if(ok) return true;
return false;
}
void add(Nod *&u, double x){
Nod *a;
a=new Nod;
a->val=x;
a->next=u;
u=a;
}
int main(){
ifile.open("fractii.in");
ofile.open("fractii.out");
Nod *a = NULL;
ifile>>n;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if((i/j==i || i%j!=0) && notIn(a,(double)i/j)){
add(a,(double)i/j);
k=2;
while(k*i<=n && k*j<=n){
cont++;
k++;
}
}
}
}
ofile<<n*n-cont;
ifile.close();
ofile.close();
return 0;
}