Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Questão B da semana 05 ("B de primos"). */
- #include <stdio.h>
- #include <math.h>
- int ehPrimo (int x) { /*Confere se o valor fornecido é primo (1) ou não é primo (0).*/
- int aux;
- if (x==2) return 1;
- else {
- if (x>2) {
- aux=x%2;
- if (aux==0) {
- return 0;
- }
- else {
- return 1;
- }
- }
- else return 0;
- }
- }
- int divisoresPrimos (int x) { /*Atribui a variavel "qtd" a quantidade de divisores de "x" com o auxilio de "ehPrimo".*/
- int i, qtd;
- qtd=0;
- for (i=1; i<=x; i++) {
- if (ehPrimo(i)==1) {
- if (x%i==0) qtd+=1;
- }
- }
- return qtd;
- }
- int f (int x, int a, int b) { /*Função responsavel por calcular o valor f(x) especificado pela "main" e com o auxilio das outras funções.*/
- int funcao;
- funcao= (a*pow(divisoresPrimos(x), 3) - (b*x));
- return funcao;
- }
- int main () { /*Recebe os valores, nomeia um valor para "x" de "l" até "r", e passa o mesmo junto de "a, b" para a função "f".*/
- int a, b, l, r, i, x, funcao;
- scanf("%d %d %d %d", &a, &b, &l, &r);
- for (i=l; i<=r; i++) {
- x=i;
- if (x==l) {
- funcao= f(x, a, b);
- }
- else if (funcao<f(x, a, b)) {
- funcao= f(x, a, b);
- }
- }
- printf("%d\n", funcao); /*Printa o maior valor possível para f(x).*/
- return 0;
- }
- /* Pelo menos essa era a ideia né, já que eu tô tomando WA de 2% =/ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement