0% found this document useful (0 votes)
64 views1 page

Drawing Edge Function in C Code

The document contains a C program that defines a function 'drawingEdge' which calculates the number of ways to draw edges in a complete graph with 'n' vertices. It utilizes modular exponentiation to compute the result efficiently, returning the value modulo 1000000007. The program includes necessary headers and utility functions for input handling and integer parsing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views1 page

Drawing Edge Function in C Code

The document contains a C program that defines a function 'drawingEdge' which calculates the number of ways to draw edges in a complete graph with 'n' vertices. It utilizes modular exponentiation to compute the result efficiently, returning the value modulo 1000000007. The program includes necessary headers and utility functions for input handling and integer parsing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <assert.

h>

#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* readline();
char* ltrim(char*);
char* rtrim(char*);

int parse_int(char*);

/*
* Complete the 'drawingEdge' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER n as parameter.
*/
const long long MODULE= 1000000007;
long long powerwith_module(long long x, long long y,const long long MODULE){
long long result =1;
while(y>0){
if(y & 1)
result=(result*x)% MODULE;
x=(x*x)% MODULE;
y=y/2;
}
return result;
}

long long drawingEdge(long long n) {


long long x= (n * (n-1) / 2);
return powerwith_module(2,x,MODULE);
}

You might also like