-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1 lines (1 loc) · 5.74 KB
/
index.html
1
<!DOCTYPE html><html lang="ro"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Calcul Cel Mai Mare Divizor Comun și Cel Mai Mic Multiplu Comun</title><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet"><style>body{font-family:'Arial',sans-serif;margin:0;padding:0;background-color:#f3f4f6;display:flex;justify-content:center;align-items:center;height:100vh;flex-direction:column}h1{text-align:center;background-color:#2196F3;color:white;padding:20px;margin:0;width:100%;font-size:1.8em}.container{width:100%;max-width:800px;padding:20px;background-color:white;border-radius:10px;box-shadow:0px 4px 8px rgba(0,0,0,0.1);text-align:center}.input-group{display:flex;flex-direction:column;align-items:center;width:100%}label{font-size:1.2em;margin:10px 0;color:#2196F3}input{padding:10px;font-size:1.2em;margin:10px 0;border-radius:8px;border:2px solid #2196F3;width:100%;max-width:400px}button{padding:15px 25px;font-size:1.2em;margin-top:10px;background-color:#2196F3;color:white;border:none;border-radius:8px;cursor:pointer;width:100%;max-width:400px;transition:background-color .3s,transform .3s;display:flex;align-items:center;justify-content:center}button:hover{background-color:#1976D2;transform:scale(1.05)}button i{margin-right:10px}.result{margin-top:20px;font-size:1.5em;font-weight:bold;color:#2196F3;text-align:center;opacity:0;animation:fadeIn 1s forwards}@keyframes fadeIn{from{opacity:0}to{opacity:1}}.step{margin-left:20px;opacity:0;transform:translateY(20px);animation:fadeInSlide .5s forwards}.step:nth-child(1){animation-delay:.2s}.step:nth-child(2){animation-delay:.4s}.step:nth-child(3){animation-delay:.6s}.step:nth-child(4){animation-delay:.8s}@keyframes fadeInSlide{from{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}.final-factors{margin-top:20px;font-size:1.5em;font-weight:bold;text-align:center;color:#2196F3}.author{text-align:center;margin-top:20px;font-size:1.2em;color:#2196F3}@media(max-width:600px){h1{font-size:1.5em;padding:15px}.input-group{width:90%}input,button{font-size:1em;padding:12px}.final-factors{font-size:1.2em}}</style></head><body><h1>Calcul Cel Mai Mare Divizor Comun și Cel Mai Mic Multiplu Comun</h1><div class="container"><div class="input-group"><label for="allNumbers">Introdu numere (separate prin virgulă sau spațiu):</label><input type="text" id="allNumbers" placeholder="Ex: 24, 18, 20"/><button onclick="calculateGCD()"><i class="fas fa-cogs"></i> Calculare Cel mai mare divizor comun</button><button onclick="calculateLCM()"><i class="fas fa-cogs"></i> Calculare Cel mai mic multiplu comun</button></div><div class="steps-container" id="stepsContainer"></div><div class="final-factors" id="gcd"></div><div class="final-factors" id="lcm"></div></div><div class="author"><p>multumesc model pentru formula si js</p></div><script>function gcd(a,b){while(b!==0){let temp=b;b=a%b;a=temp}return a}function primeFactors(num){let factors=[];for(let i=2;i<=num;i++){while(num%i===0){factors.push(i);num/=i}}return factors}function calculateGCD(){let allNumbers=document.getElementById("allNumbers").value;allNumbers=allNumbers.includes(",")?allNumbers.split(","):allNumbers.split(" ");let error=false;for(let index=0;index<allNumbers.length;index++){const element=allNumbers[index].trim();if(isNaN(element)||!Number.isInteger(Number(element))||element===""){error=true;break}}if(!error&&allNumbers.length>1){let numbers=allNumbers.map(num=>parseInt(num.trim()));let stepsHTML='';let primeFactorLists=[];numbers.forEach(num=>{let factors=primeFactors(num);let stepHTML=`Numărul ${num} este descompus astfel:\n`;let currentNum=num;factors.forEach(factor=>{stepHTML+=`<div class="step">${currentNum} | ${factor}</div>`;currentNum/=factor});stepHTML+=`<div class="step">1 | 0</div>`;stepsHTML+=stepHTML+'<br><br>';primeFactorLists.push(factors)});document.getElementById("stepsContainer").innerHTML=stepsHTML;let gcdFinal=numbers[0];numbers.slice(1).forEach(num=>{gcdFinal=gcd(gcdFinal,num)});document.getElementById("gcd").innerHTML=`Cel mai mare divizor comun = ${gcdFinal}`}else{document.getElementById("gcd").innerHTML="Te rog introdu numere valide, separate prin virgulă sau spațiu.";document.getElementById("stepsContainer").innerHTML=""}}function calculateLCM(){let allNumbers=document.getElementById("allNumbers").value;allNumbers=allNumbers.includes(",")?allNumbers.split(","):allNumbers.split(" ");for(let index=0;index<allNumbers.length;index++){const element=allNumbers[index].trim();if(isNaN(element)||!Number.isInteger(Number(element))||element===""){error=true;break}}if(!error&&allNumbers.length>1){let numbers=allNumbers.map(num=>parseInt(num.trim()));let stepsHTML='';let primeFactorLists=[];numbers.forEach(num=>{let factors=primeFactors(num);let stepHTML=`Numărul ${num} este descompus astfel:\n`;let currentNum=num;factors.forEach(factor=>{stepHTML+=`<div class="step">${currentNum} | ${factor}</div>`;currentNum/=factor});stepHTML+=`<div class="step">1 | 0</div>`;stepsHTML+=stepHTML+'<br><br>';primeFactorLists.push(factors)});document.getElementById("stepsContainer").innerHTML=stepsHTML;let lcmFactors={};let lcmFinal=1;primeFactorLists.forEach(factors=>{factors.forEach(factor=>{let count=factors.filter(f=>f===factor).length;if(!lcmFactors[factor]||count>lcmFactors[factor]){lcmFactors[factor]=count}})});let lcmString='';for(let factor in lcmFactors){lcmString+=`${factor}¹•`;lcmFinal*=Math.pow(factor,lcmFactors[factor])}lcmString=lcmString.slice(0,-1);document.getElementById("lcm").innerHTML=`Cel mai mic multiplu comun = ${lcmFinal} (${lcmString})`}else{document.getElementById("lcm").innerHTML="Te rog introdu numere valide, separate prin virgulă sau spațiu.";document.getElementById("stepsContainer").innerHTML=""}}</script></body></html>