TOPIC
PROBLEM 1707 - URI Fórum 1.0
This topic was solved and cannot recieve new replies.
-
FelipeDerkian replied 7 years ago
MODvaleu mano pela dica... vou tentar implementar dessa forma como falou. valeu
-
FelipeDerkian replied 7 years ago
MODpois é cara... bolei esse outro aqui.. usando divisão, mas ainda esta dando TLE..... vou ter que fazer por range para ser mais rapido.....
#include <stdio.h> #include <stdlib.h> int main(){ unsigned long long int a, b, i , soma =0, p =0,s=0 ,t=0; while(scanf("%llu %llu",&a,&b)!= EOF){ soma =0 , p=0 , s=0,t=0; if(a < b){ for(i=a;i<=b;i++){ if(i%2!=0){ p = i/1000000000; soma+=p; p = i%1000000000; s = p/100000000; soma+=s; p = i%100000000; s = p/10000000; soma+=s; p = i%10000000; s = p/1000000; soma+=s; p = i%1000000; s = p/100000; soma+=s; p = i%100000; s = p/10000; soma+=s; p = i%10000; s = p/1000; soma+=s; p = i%1000; s = p/100; soma+=s; p = i%100; s = p/10; soma+=s; s = p%10; soma+=s; } } printf("%llu\n",soma); } else if(a > b){ for(i = a ; i >= b ; i--){ if(i%2!=0){ p = i/1000000000; soma+=p; p = i%1000000000; s = p/100000000; soma+=s; p = i%100000000; s = p/10000000; soma+=s; p = i%10000000; s = p/1000000; soma+=s; p = i%1000000; s = p/100000; soma+=s; p = i%100000; s = p/10000; soma+=s; p = i%10000; s = p/1000; soma+=s; p = i%1000; s = p/100; soma+=s; p = i%100; s = p/10; soma+=s; s = p%10; soma+=s; } } printf("%llu\n",soma); } } }
-
FelipeDerkian replied 7 years ago
MODarrumei essa parte .. mais ainda esta dando TLE...
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { unsigned long long int a, b, soma; int i; while( scanf("%llu %llu",&a,&b) != EOF) { soma =0; char num[100000]; char t[3]; if(a<b){ for( i = a; i <= b; i++ ) { if(i%2!=0) { sprintf(num,"%d",i); int j; for(j=0; j<strlen(num); j++) { t[0] = num[j]; t[1] = '\0'; int pegarInt = atoi(t); soma+=pegarInt; } } } } else if(a > b){ for( i = a; i >= b; i-- ) { if(i%2!=0) { sprintf(num,"%d",i); int j; for(j=0; j<strlen(num); j++) { t[0] = num[j]; t[1] = '\0'; int pegarInt = atoi(t); soma+=pegarInt; } } } } printf("%llu\n",soma); } }
se puder ajudar fico agradecido...
-
FelipeDerkian replied 7 years ago
MOD#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { unsigned long long int a, b, soma; int i; while( scanf("%llu %llu",&a,&b) != EOF) { soma =0; char num[100000]; char t[3]; for( i = a; i <= b; i++ ) { if(i%2!=0) { sprintf(num,"%d",i); int j; for(j=0; j<strlen(num); j++) { t[0] = num[j]; t[1] = '\0'; int pegarInt = atoi(t); soma+=pegarInt; } } } printf("%llu\n",soma); } }
alguém pode me ajudar? porque não esta sendo aceito se esta certo?
-
GuilhermeA.deSanti replied 8 years ago
Hi, I am trying for days to solve these problem and am getting presentation error every time I submit my code. My code is close to these (I omitted the calculus part, there is only the presentation part):
public static void main(String[] args) throws IOException { BufferedReader bi = new BufferedReader(new InputStreamReader(System.in)); String line; long x; long y; long sum = 0; while ((line = bi.readLine()) != null) { String[] lineSplit = line.split(" "); x = Long.valueOf(lineSplit[0]); y = Long.valueOf(lineSplit[1]); if (x < y) { sum = (f3(y) - f3(x - 1)); } else { sum = (f3(x) - f3(y - 1)); } System.out.print(sum); System.out.print("\n"); } System.out.print("\n"); }
The f3() is the function that calculates the result to be printed on the output. Is there any trick to print the results without getting the presentation error? Thank you.