We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #245: Coresilience
Project Euler #245: Coresilience
Sort by
recency
|
15 Discussions
|
Please Login in order to post a comment
Mock interviews are simulated sessions that replicate the actual UPSC interview environment. These sessions are designed to provide a realistic experience, with expert feedback helping candidates refine their strategies. They assess various qualities like mental alertness, clear thinking, communication skills, and leadership potential. Engaging in mock interviews significantly boosts a candidate's confidence and readiness.
Prepare for UPSC and IAS exams with Delhi's premier online coaching center. Our comprehensive syllabus covers all subjects, ensuring you have the knowledge and skills needed to excel. Join our esteemed faculty and gain access to interactive classes, study materials, mock tests, and personalized guidance. Start your journey towards success today.
From my perspective, while the problem itself is not as complicated as I expected, it was figuring out how to design an eligible efficient algorithm that was the actual problem.
UPSC Previous Year Question Papers:- To solve previous years UPSC question papers, nay considers scrupulously fathoming, important questions for you to answer. Furthermore, doing so prepares you in different ways to perform better when facing the Civil Services Examination. Website:- https://www.eliteias.in/why-do-you-need-to-refer-to-previous-years-upsc-question-papers/
import scala.math.BigInt
object ProjectEuler245Coresilience { val eulerTotient:BigInt => BigInt = n => { var result: BigInt = n var i: BigInt = 2 var tmp: BigInt = n while (i * i <= tmp) { if (tmp % i == 0) { while (tmp % i == 0) { tmp /= i } result -= result / i } i = i + 1 } if (tmp > 1) result -= result / tmp result }
val coresilience: BigInt => BigInt = n =>{ a= n-eulerTotient(n) (a / a.gcd(n-1)) }
val sumOfUnitFractions:BigInt => BigInt = n => { var sumOf: BigInt = 0 for (i: BigInt <- BigInt(2) to n) { if (coresilience(i) == 1) { sumOf += i } } sumOf }
var a: BigInt = 0
def main(args: Array[String]): Unit = { val stdin = scala.io.StdIn val test = stdin.readInt println(sumOfUnitFractions(test)) } }
Here is my solution with Scala and I couldn't go further optimization. Any help??