Skip to content
Open

A1 #248

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions binary search.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<stdio.h>

int binary_search(int a[],int l,int u,int choice)//assumes array is sorted
{
int m;
while(l<u)
{
m=(l+u)/2;

if(a[m]==choice)
return m;

if(choice<a[m])
u=m-1;
else
l=m+1;
}

if(a[l]==choice)
return l;
else
return -1;
}

int main()
{
int a[10]={1,2,2,3,4,5,6,7,8,9};

int c=binary_search(a,0,9,2);
if(c==-1)
printf("NON existing\n");
else
printf("EXISTING at index %d\n",c);

return 0;
}
28 changes: 28 additions & 0 deletions d_discrete.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<stdio.h>

int main()
{
unsigned long long p,test,x,y,m,n;

scanf("%llu",&test);

for(;test>0;test--)
{
scanf("%llu%llu%llu",&x,&y,&m);

x%=m;

p=1;

for(;y>0;y/=2)
{
if(y & 1)
p=(p*x)%m;

x=(x*x)%m;
}
printf("%llu ",p);
}

return 0;
}