twarzo's blog

By twarzo, 12 years ago, In English

I am getting wrong answer in http://www.spoj.com/problems/FIBFUNCH/ Please somebody help.

include<stdio.h>

int main() { long long int t,n,x,y,s=0,m,i=0; scanf("%lld",&t); while(t--) {s=0; scanf("%lld%lld%lld%lld",&x,&y,&n,&m); s=(x%m+y%m)%m; for(i=2;i<n;i++) { y=x+y; x=y-x; s+=(y%m); s%=m; } printf("%lld\n",s); } return 0; }

Full text and comments »

  • Vote: I like it
  • -11
  • Vote: I do not like it

By twarzo, 12 years ago, In English

Majid is a 3rd-grade elementary student and quite well in mathematics. Once, Majid's teacher asked him to calculate the sum of numbers 1 through n.

Majid quickly answered, and his teacher made him another challenge. He asked Majid to calculate the sum of the digits of numbers 1 through n.

Majid did finally find the solution. Now it is your turn, can you find a solution? Input

Two space-separated integers 0 <= a <= b <= 109.

Program terminates if a and b are -1. Output

The sum of the digits of numbers a through b. Example

Input: 1 10 100 777 -1 -1 Output: 46 8655

can anyone help me with this ?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it