Varianta 72 / Subiectul 3 / Problema 3 |
#include<fstream.h> #include<math.h> ofstream f("sir.out"); float Ecuatie(int a, int b, int c) { int d; float x1,x2; d=b*b-4*a*c; if(d<0) return -32000; else if(d==0) { x1=-b/(2*a); if(x1>0) return x1; else return -32000; } else { x1=(-b-sqrt(d))/(2*a); x2=(-b+sqrt(d))/(2*a); if(x1>x2) if(x1>0) return x1; else return -32000; else if(x2>0) return x2; else return -32000; } } void main() { int k,n; float x; cin>>k; x=Ecuatie(1,1,-2*k); n=floor(x); if(n==x) f<<n; else f<<k-n*(n+1)/2; f.close(); } |