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.
Primitive Problem
Primitive Problem
Sort by
recency
|
895 Discussions
|
Please Login in order to post a comment
What is Website KissAsian and Is it Legal? KissAsian is a website that offers a wide range of Asian dramas, movies, and TV shows for streaming. It primarily focuses on content from East Asian countries such as South Korea, China, Japan, Taiwan, and Thailand. Users can watch these shows for free on the platform.
Bagatelle Restaurants redefine the art of dining with their distinctive blend of gourmet cuisine and vibrant ambiance. With locations spanning across renowned cities worldwide, each Bagatelle establishment promises an unforgettable experience characterized by impeccable service and culinary innovation. Guests are invited to embark on a culinary journey that celebrates the essence of French Mediterranean cuisine, with a modern twist.
ZAB Sports Apparel specializes in creating top-notch custom sports uniforms for various sports teams, clubs and individuals. Our wide selection includes basketball uniforms, soccer uniforms, soccer uniform kits, american football uniforms. We prioritize durability, performance, and personalized design to help athletes succeed and stand out in their chosen sport. We also specialize in creating customized hoodies, t-shirts, polo shirts, sweatpants, sweat shirts for team members, groups, and streetwear brands.
Watch Savdhaan India Today Episode In HD High Quality, Watch Desi serials Savdhaan India Complete Episodes By Star Plus and Hotstar in HD.
This solution with python , but has some test faild because of Time limit exceeded .
import math
import os
import random
import re
import sys
def power(x, y, p):
result = 1
x = x % p
while y > 0:
if y & 1:
result = (result * x) % p
y = y >> 1
x = (x * x) % p
return result
def is_primitive_root(g, p, factors):
for factor in factors:
if power(g, (p - 1) // factor, p) == 1:
return False
return True
def find_primitive_roots(p):
primitive_roots = []
factors = set()
# Find prime factors of p-1
for i in range(2, int(math.sqrt(p-1)) + 1):
if (p - 1) % i == 0:
factors.add(i)
factors.add((p - 1) // i)
for g in range(2, p):
if is_primitive_root(g, p, factors):
primitive_roots.append(g)
return primitive_roots
def smallest_primitive_root(p):
primitive_roots = find_primitive_roots(p)
return min(primitive_roots)
if name == 'main':
p = int(input().strip())
smallest_root = smallest_primitive_root(p)
total_roots = len(find_primitive_roots(p))
print(smallest_root, total_roots)