c - printing sheet to fill the square sheet with the stamps without any overlapping -
i have written following c program online course. seems working , giving relevant output, when submit program, told gives "wrong answer".
#include <stdio.h> int main() { long int n; scanf(“%ld”,&n); if(n>1) { if(n%2||n%3) printf(“yes”); else printf(“no”); } else if(n==1) { printf(“no”); } return 0; }
this program supposed do:
ted (the popular talking bear) has been given job @ printing firm. looking @ previous employment record, firm watching strictly on work product. recently, has been assigned task print on square sheet of dimension nxn. may think of sheet containing n2 cells of dimension 1x1 each. since, ted lazy bear, somehow steals 2 stamps, horizontal printing stamp covers 1*2 block , vertical printing stamp covers 3*1 block. may use these 2 stamps in order , many times wants. sheets old, if sheet stamped twice @ cell, tear off. now, there shipment of sheets coming varying sizes. observes in of cases not possible fill square sheet no overlapping stamps. so, asks in deciding whether possible fill square sheet stamps without overlapping.
input consists of single integer n denoting side of square sheet.
output single line containing “yes” (without quotes) if possible fill square sheet without overlapping stamps , “no” (without quotes) otherwise.
constraints:
1 ≤ n ≤ 106
sample input:
2
sample output:
yes
how can fix program?
i don't know if algorithm correct, think instead of:
if(n%2||n%3)
you wanted write:
if(n%2 == 0 || n%3 == 0)
here n%2 == 0
means n
divisible 2.
Comments
Post a Comment